Microsoft and Canonical have teamed up to add systemd support to the Windows Subsystem for Linux, allowing a larger number of compatible apps to be installed.
systemd is a Linux software application that acts as the system and service manager for initializing daemons/services during the bootup of the operating system. Systemd also supports tools that allow Linux admins to easily manage and control these services after they have been started.
As systemd is responsible for launching all other services, it runs as the first process (PID 1) created by the Linux kernel on startup. All other initial startup services are then started and managed by systemd, as shown by the process tree below from Ubuntu.
As WSL currently uses init as the system and services manager, Linux applications that require systemd, such as Snap, microk8s (Kubernetes), and systemctl, do not work correctly.
WSL now supports systemd
Yesterday, Microsoft and Canonical announced that the latest preview version of the Windows Subsystem for Linux in Windows 11 Insider builds now supports systemd, allowing you to install applications that require the service manager.
“Supporting systemd required changes to the WSL architecture. As systemd requires PID 1, the WSL init process started within the Linux distribution becomes a child process of the systemd,” explained Microsoft’s Craig Loewen in a new announcement.
“Because the WSL init process is responsible for providing the infrastructure for communication between the Linux and Windows components, changing this hierarchy required rethinking some of the assumptions made with the WSL init process.”
If you are running a Windows 11 Insider build, you can upgrade to the WSL 0.67.6 preview or later using the
wsl --update command. Once it is finished updating, you can check your installed version using the
wsl --version command, as shown below.
You now need to enable systemd by launching your desired WSL Linux distribution and adding the following lines to /etc/wsl.conf:
As the /etc folder is owned by root, you need to use sudo with your favorite console editor to edit the file. For example,
sudo vi /etc/wsl.conf.
It should be noted that this process needs to be done for each distro you wish to enable systemd.
Now close your WSL distro window, and from the Windows 11 command line (Command Prompt or PowerShell), shut down your WSL distros with the
wsl.exe --shutdown command.
Start your Linux distribution again, and you will see that systemd is running as PID 1, indicating it is running as the service and system manager for WSL.
For more information on how systemd works in WSL and how it will enable you to run more applications in WSL, you can watch this video by Microsoft’s Craig Loewen and Canonical’s Oliver Smith.