WSL: System has not been booted with systemd as init system (PID 1)

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche

Script to enable systemd support on current Ubuntu WSL2 images from the Windows store. Script is unsupported and will no longer be maintained, but will be up here because it is used by quite some people. I am not responsible for broken installations, fights with your roommates and police ringing your door ;-).


Error

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down


Cause

This is because systemd is not enabled by default in WSL 2.


Solution

  • Enable systemd support on WSL 2 with following commands:
#Install git
sudo apt install git
 
#Run the script
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
# Enter your password and wait until the script has finished
  • Restart your WSL and try running
systemctl

Source: https://github.com/DamionGans/ubuntu-wsl2-systemd-script


Troubleshooting: Cannot execute daemonize to start systemd

Maybe you broke your WSL 2 Linux with the script above, then you can undo the changes by following steps:

  • Enter WSL as root user
wsl -u root
  • Disable the systemd start script, do the following:
nano /etc/bash.bashrc
  • Put a # on the start of the line that says "source /usr/sbin/start-systemd-namespace"