kotoyuuko

CORE

昨日より、明日より、笑える今が一番大好き。
github
telegram
email

Using systemd on WSL

Preface#

WSL developed by Microsoft is very useful. However, because they use a custom init startup, using systemd will result in the following error:

System has not been booted with systemd as init system (PID 1). Can’t operate.

Using systemd with genie#

genie creates a PID namespace to enable the use of systemd on WSL.

genie is built on .NET Core 3 and requires the installation of the .NET Core runtime environment before use. Installation instructions can be found in Microsoft's official documentation.

Afterwards, genie can be installed as follows:

curl -s https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh | sudo bash
sudo apt install systemd-genie

Using genie is quite simple:

# Start the systemd environment
genie -i
# Start the systemd environment and open a shell in the environment
genie -s
# Start the systemd environment and run a command in the environment
genie -c command

Boot Startup#

Simply configuring the above is not enough to enable services to start at boot. Further configuration for startup is required.

First, enter the WSL environment and create a /etc/init.wsl file with the following content:

#!/bin/bash
/usr/bin/genie -i

Then return to Windows, use the Win + R key combination to open the Run dialog, enter shell:startup to access the startup directory.

Create a vbs file with any name and the following content:

Set ws = CreateObject("Wscript.Shell")
ws.run "wsl -d Debian -u root /etc/init.wsl", vbhide

Note: Replace Debian in the parameter with the name of the WSL distribution you are using.

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.