None of the systemd commands are working inside WSL( Ubuntu Bash 18.04). When I ran sudo systemctl is-active kubelet, error is output: System has not been booted with systemd as init system (PID 1). Can't operate.
: running command: sudo systemctl is-active kubelet
How to enable systemd feature in WSL? Whats the way to get rid of System has not been booted with systemd
5 Answers
When using WSL2 you can use:
sudo service docker startThis command basically execute the script /etc/init.d/docker.
Some customization, like specifying HTTP proxy, is possible via the script /etc/default/docker.
Systemd is not supported in WSL at this time. More information can be found with this GitHub issue.
Furthermore, Docker does not (at the time of writing this) work on top of WSL, which means Kubelet won't be of much use. In order to run Kubernetes locally, you can use Docker for Windows which includes Kubernetes support, or you can use Minikube to run a VM with Hyper-V or Virtualbox.
3Windows Subsystem for Linux (WSL) 2 introduces a significant architectural change as it is a full Linux kernel built by Microsoft, allowing Linux containers to run natively without emulation.
Before you install the Docker Desktop WSL 2 backend, you must complete the following steps:
Install Windows 10, version 1903 or higher. Enable WSL 2 feature on Windows.
Source - Docker Desktop WSL 2 backend
To find out which version of Windows your device is running, press the Windows logo key + R, type winver in the Open box, and then select OK.
Systemd is NOT supported in WSL but there is a workaround for this - Script to enable systemd support on current Ubuntu WSL2 images from the Windows store.
0Hack Systemd in WSL2
Systemd is not native in WSL2, but Shayne found a way to hack it:
The experience is quite destabilizing on firt approch but it works for most of my usage: docker, minikube (--driver=none), systemd services.
PS: Mind to always connect to your user (bash $USER) before using it. Otherwise you won't have much access to your profile configurations (~/.profile or ~/.bash_profile).
Using Systemd Genie
Arkane published a way to orchestrate namespace (or bottle) in systemd for WSL2:
After installing connect to your profile through genie:
genie -c bashAt this time, only Ubuntu 18.04 and 19.10 works. There is no package for Ubuntu 20.04 for the moment (I am exciting this moment).
Docker and Minikube also work in this configuration as native (--driver=none).
You can boot systemd fairly easily in WSL2 using bubblewrap:
# pacman -S bubblewrap # or apt, etc.
# bwrap --dev-bind / / --unshare-pid --as-pid-1 /usr/lib/systemd/systemdIt will not print anything to the current TTY if it starts successfully, but if you run htop etc. in another TTY, you will see that it booted and started configured services.
You can then manually enable OpenSSHd by symlinking /usr/lib/systemd/system/sshd.service to /etc/systemd/system/. Configure your keys in /root/.ssh, start systemd, and you should be able to SSH in.