How to enable systemd in WSL: Up until very recently, members of the WSL community were responsible for developing their own workarounds to integrate systemd support into their distributions. Regardless of how you feel about systemd, the fact is that it is an essential tool for a number of different activities. However, as of right now, it is an official part of WSL.
In due time, it will no longer require much of your attention because it will merely exist in its current state. On the other hand, it’s possible that you don’t want it and need to know how to turn it off.
The good news is that manually enabling or disabling systemd in WSL is a straightforward process that, for the most part, follows the same sequence of actions.
What is systemd?
The official definition of systemd is as follows: “ystemd is a collection of fundamental programs that are used to construct a Linux system. It offers a system and service manager that operates with the PID 1 process ID and begins the process of starting the remainder of the system.”
On a more fundamental level, it is something that you will need to have if you wish to have access to things like snap packages on Ubuntu. Under point of fact, Microsoft collaborated with Canonical to ensure that systemd would function correctly in WSL.
When you run many Linux distributions on bare metal or on a virtual machine, systemd is the daemon that manages the system. With the inclusion of it to WSL, Microsoft has checked off another item on its list to make the Linux-on-Windows experience as near as possible to the real thing.
You may also like How to Uninstall Windows 10 Operating System
System requirements
You will need to be running WSL version 0.67.6 or later in order to access the systemd command line interface. You should already be on a supported build if you are utilizing the version that is available from the Microsoft Store or if you have just installed WSL on your machine.
Launch PowerShell and enter in the following command to determine the version of WSL you have installed on your system.
wsl –version
If you need to update to a version that is supported, you can do so by issuing the following command from within the same PowerShell window:
wsl –update
You will obtain the most recent version from the Microsoft Store by default; but, if you would prefer to obtain it from GitHub, you may include —web-download to the end of the script to obtain it from that location instead. You can also manually download the file from the GitHub repository. This option is also accessible.
Users that install Ubuntu Preview on WSL ought to have systemd readily available by default.
How to enable and disable the systemd in WSL
Only once you have enabled systemd will you be able to make use of systemd even if you have access to it. Because distribution developers can now perform this action on their own, there may come a time when it is already enabled by default.
On the other hand, if yours does not already have it enabled, you will need to activate it. And if you don’t want it, you might want to know how to turn it off in case you accidentally turn it on. The wsl.conf file, as its extension suggests, is a configuration file for each of your different WSL distributions. This is where all of the magic happens and where it is handled. Because systemd cannot presently be activated on a system-wide basis, you will need to carry out these steps in each of the specific distributions that you use.
The following command should be used to open the wsl.conf file in the Linux distribution of your choice:
sudo nano /etc/wsl.conf
This will launch the Nano text editor, but if you haven’t already made a configuration file, it will be completely empty when it first opens. It is necessary to include the following instructions to activate systemd:
[boot]
systemd=true
To deactivate it, you can either delete the instruction entirely or set it to false, achieving the same outcome. Setting it to false, at the very least, simplifies the process of reactivating it in the future.
From this point forward, you should save the file and exit (using CTRL+O to save the file and CTRL+X to depart), after which you should shut the Linux tab and go back to the PowerShell prompt. In order to guarantee that systemd is enabled, you will need to power down WSL entirely, wait for at least eight seconds, and then power it back up again. To completely turn off the system, use this command:
wsl.exe –shutdown
Open up your Linux distribution once more after the eight-second delay, and systemd should have been activated by this point. It’s possible that the initial boot will take a little longer than usual, but once it’s done, you can verify that systemd is running by executing this command:
systemctl list-unit-files —type=service
Assuming everything went according to plan, this should produce a comprehensive list of all services currently active. You will notice an error message if systemd has not been activated on your computer.
If you want to use snap to install packages, having systemd already installed is absolutely necessary, at least on Ubuntu. This is one of the most obvious reasons. Following the activation of systemd, you will be able to install packages, such as Nextcloud, by entering:
sudo snap install nextcloud
If you are interested in learning more about the snap framework, you may look over the complete library on snapcraft.io.