What is Systemd?
Systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system. Systemd is installed by default in several well-known distributions, including Ubuntu, Debian, and others. With this change, WSL will be even more comparable to running your preferred Linux distributions on bare metal machines and will allow the usage of applications that require systemd support. A few examples of Linux applications that depend on systemd are snap, microk8s, and systemctl. According to Microsoft: Read: How to access Windows Subsystem for Linux files on Windows Given that this changes how WSL behaves when booting up, we wanted to be careful about applying this to user’s already existing WSL distros. So currently you need to opt-in to enable systemd for a specific WSL distro, and we will monitor feedback and investigate making this behavior by default in the future.
How to enable Systemd in Windows Subsystem for Linux (WSL)
Up until now as of the time of writing this post, the Windows Subsystem for Linux (WSL) community has been building its ways to implement systemd. But, coming on the heels of a partnership with Canonical, Microsoft has now officially implemented systemd in WSL. With the systemd support available in WSL, you can now run systemd inside of your WSL distros, empowering you to do more with your Linux workflows on your Windows machine. To get systemd on your machine, you will need to do the following:
Ensure you are running WSL version 0.67.6 and above
If have enabled WSL through PowerShell and have not downloaded it from the Microsoft Store on your device, you won’t have systemd initially. Only users running the Insider build of Windows 11, or those using WSL as downloaded from the Microsoft Store will have it. If you’re using Ubuntu Preview on WSL, systemd is being added automatically. So, to check if you have the supported version of WSL, simply open Windows Terminal, and in the PowerShell console, run the following command: From the output, if the WSL version is 0.67.6 or earlier, you can head over to the Microsoft Store and download WSL. Alternatively, PC users especially if you’re not a Windows Insider, can download the latest release from the WSL GitHub repo. In the future, all users will get systemd support added. To check for any updates to WSL, run the command below In PowerShell: Read: Fix Windows Subsystem for Linux Errors, Problems, and Issues
Set the systemd flag set in your WSL distro settings
Once you have verified you are running the supported version of WSL required for systemd, you will need to edit the wsl.conf file (a configuration file found in any WSL Linux distribution and allows you to configure on a per-distro basis, rather than modifying the general WSL settings) to ensure systemd starts up on boot. To perform this task, do the following:
Run your editor with sudo privileges and then add the following lines:
Once done, save the file and then exit.Now, you can close your WSL distro Windows and run the following command in PowerShell to restart your WSL instances.
Upon launch, you should have systemd running. To check and show your services’ status, run the command below:
Read: How to set Linux Distribution version to WSL1 or WSL2 in Windows That’s how you can enable Systemd in Windows Subsystem for Linux (WSL)!
How do I boot to systemd as init?
To boot under systemd, select the boot menu entry that you created for the purpose. If you haven’t created the boot menu entry, just select the entry for your patched kernel, edit the kernel command line directly in grub and add the following line: init=/lib/systemd/systemd.