NOTE: If you have Windows 11 there is now an official way to do this in WSL 2, use it if possible - see MS post here (WINDOWS 11 ONLY)
This guide will enable systemd
to run as normal under WSL 2. This will enable services like microk8s
, docker
and many more to just work
during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.
-
To enable
systemd
under WSL we require a tool calledsystemd-genie
-
Copy the contents of
install-sg.sh
to a new file/tmp/install-sg.sh
:cd /tmp wget --content-disposition \ "https://gist.githubusercontent.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh"
-
Make it executable:
chmod +x /tmp/install-sg.sh
-
Run the new script:
/tmp/install-sg.sh && rm /tmp/install-sg.sh
-
Exit the WSL terminal and shutdown the WSL env:
wsl --shutdown
-
To open a new WSL terminal with
systemd
enabled, run:wsl genie -s
-
Prove that it works:
sudo systemctl status time-sync.target
Hi, The script depends on Microsoft Dotnet-sdk-5.0 that is replaced by Dotnet-sdk-6.0 (do not coexist). This is creating a dependency issue with the new distros or environments with Dotnet-sdk-6.0. Is it possible to update the script to support v6.0 or both? See the error below:
`Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
dotnet-runtime-deps-5.0 : Depends: libssl1.0.0 but it is not installable or
libssl1.0.2 but it is not installable or
libssl1.1 but it is not installable
systemd-container : Depends: systemd (= 249.11-0ubuntu3) but 249.11-0ubuntu3.3 is to be installed
Recommends: libnss-mymachines but it is not going to be installed
E: Unable to correct problems, you have held broken packages.`