User systemd in WSL2 without genie

· macaylamarvelous81's blog

WSL2 systemd support only works for system level, not users.

By setting systemd = true at boot in /etc/wsl.conf, systemd support can be enabled. However, if you want to use user services (~/.config/systemd/user), you need to launch WSL differently.

Since WSL doesn't create the user dbus1, you'll get an error when using systemctl with the --user option. However, as noted by @psmolkin in the related issue1, the dbus will be created if you su into your user. The command will look like this:

wsl -u root -- su uname

with uname as the username. You will have to shutdown wsl prior to this, and if you log into WSL regularly after this (wsl) it will be reverted and a shutdown is required again.

In my case, I started WSL on login with Task Scheduler and a vbscript. So, I wrote my vbscript like this:

set ws = wscript.createobject("wscript.shell")
ws.run "C:\Windows\System32\wsl.exe -d Ubuntu -u root -- su - uname",0

which starts wsl systemd, including lingering users' services. I also logged into WSL with Windows Terminal, so I set the profile command to:

wsl -d Ubuntu -u root -- su - uname

I inserted a hyphen between su and my username so I would not preserve the environment and start at root's home directory.


  1. (Related GitHub issue)[https://github.com/microsoft/WSL/issues/8842] ↩︎ ↩︎