Fix WSL2 Ubuntu System Files From Windows
I was following these steps to set up SystemD in my WSL2 Ubuntu 20.04 distribution and didn't validate as I should have before restarting. Now when I try to start (as my normal user or as root
), it hangs with:
/usr/sbin/enter-systemd-namespace: line 10: /usr/sbin/daemonize: No such file or directory
How can I revert the /etc/bash.bashrc
changes to recover? I've tried editing via the \\wsl$\\<distro>\...
path from Windows using Notepad, but don't have permissions (even when running as administrator).
I see you already recovered, and that was a good solution. In the future, also consider:
wsl -u root -e bash --noprofile --norc
This should get you into a shell without the offending startup scripts running. You can also use sh
if needed.
Also, most of the Systemd scripts or instructions for WSL are pretty complicated, because they try to "do everything". To do a "quick and dirty" Systemd that runs, but may have some limited functionality, you can start with:
sudo -b unshare --pid --fork --mount-proc /lib/systemd/systemd --system-unit=multi-user.target
Wait a few seconds for ps -ef
to "settle down" while Systemd starts up, then:
sudo -E nsenter --all --wd="$PWD" -t $(pgrep -xo systemd) runuser -P -l $USER -c "exec $SHELL"
That should get you into a usable Systemd environment in WSL2/Ubuntu. The main limitation is that you won't be able to run Windows executables in that session. But that shouldn't be necessary for the Kubernetes tutorial.
Once you have that running, then you can build up to the "full Systemd" scripts.
The new/offending line was line 4 in /etc/bash.bashrc
.
I was able to remove it from the Windows command prompt via:
wsl -u root --exec sed -i 4d /etc/bash.bashrc
I was then able to get logged back in to my shell and clean up the problems.