I am using the WSL for Windows. I have tried multiple Ubuntu Versions, but every version shuts down right after I enter my password. If I restart my PC, it's fine at first. But if want to open another WSL-Window the problem reoccurs. It's really frustrating.
I added this piece of code to /etc/profile.d/00-wsl2-systemd.sh:
SYSTEMD_PID=$(ps -efw | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')if [ -z "$SYSTEMD_PID" ]; then sudo /usr/bin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target SYSTEMD_PID=$(ps -efw | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')fiif [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then exec sudo /usr/bin/nsenter -t $SYSTEMD_PID -a su - $LOGNAMEfi