Short answer:
- You still shouldn't use Linux shutdown methods on a WSL2 distribution.
- You are ultimately going to need to
wsl --shutdown
and restart in order to fully recover.
More details:
Under the updated WSL that provides Systemd support, you can now run certain "shutdown" commands, but that doesn't mean you should. This includes:
sudo systemctl poweroff
sudo systemctl halt
sudo systemctl reboot
- Choosing any of the related Power-off or restart options in a Desktop Manager (Gnome, Xfce4, and others).
In all of these cases, Systemd replaces itself with the systemd-shutdown
(see man page for more details), which continues running even after WSL reports that the distribution is no longer running (via wsl.exe -l -v
).
I'm taking a bit of a guess here, but when WSL attempts to restart Ubuntu, it seems that it can't load its own init
because PID1 is still "occupied" by systemd-shutdown
(or perhaps because systemd
isn't there to call it).
$ ps -fp 1
UID PID PPID C STIME TTY TIME CMD
root 1 0 1 22:23 ? 00:00:00 /lib/systemd/systemd-shutdown halt --timeout 90000000us --log-level 6 --log-target console
As a result, much of the "normal" WSL startup does not occur. This includes the Windows drive mounts as well as the binfmt_misc
registration that allows WSL to run Windows commands. But not, apparently, the attempt to append the Windows path to the Linux path in the base environment.
After the timeout (90 seconds) that you see in the command arguments above, systemd-shutdown
will terminate, and the WSL distribution will terminate (again) with it.
You could also terminate with wsl --terminate <distro_name>
from PowerShell.
In either case, the newly restarted Ubuntu will not exhibit the error messages listed in the question.
However, you will still need to wsl --shutdown
and restart before you will regain access to the ability to run Windows commands. The "corruption" of binfmt_misc
will actually extend to all WSL2 distributions running on your system until a wsl --shutdown
.