Starting services on WSL2 with systemd

Starting services on WSL2 with systemd

WSL2 is a great way to run Linux alongside Windows 10. However systemd doesn't work in it yet.

Luckily, there is a 3rd-part solution - genie.  It allows to run systemd as a PID 1. While it's not a full replacement with a number of known issues, it allows to run some common Linux daemons on your WSL2 instance, for example docker or Syncthing.

Here are steps we use Ubuntu 20.04, if you use another distro, please, check docs in the project's repo.

# add Microsoft repo with .Net 3.1 runtime
wget -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

# add repo with genie
curl -s | sudo bash

sudo apt update
sudo apt install systemd-genie

Update the content of /usr/lib/genie/deviated-preverts.conf to:

  "daemonize": "/usr/bin/daemonize",
  "mount": "/bin/mount",
  "runuser": "/sbin/runuser",
  "systemd": "/bin/systemd"

Then genie -i is enough to start systemd. However this step will be required on every boot of windows, but it's possible to automate this step with Task Scheduler.

Just run wsl.exe genie -i on your user log on. That's it.

Show Comments