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
This does not work with Windows 10 Enterprise Edition (21H2) with WSL2 (Kernal v5.10.102.1) Ubuntu 22.04 LTS (Jammy Jellyfish) (see [https://apps.microsoft.com/store/detail/ubuntu-2204-lts/9PN20MSR04DW] for Microsoft Store distro)
I also modified install-sg.sh to change UBUNTU_VERSION="20.04" to UBUNTU_VERSION="22.04", with no avail. It also looks like arkane-systems/genie is now at Version 2.3, from the embedded version of 1.44 in the /tmp/install.sg.sh script.
root:/tmp# /tmp/install-sg.sh && rm /tmp/install-sg.sh
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:5 https://download.webmin.com/download/repository sarge InRelease
Hit:6 https://download.webmin.com/download/repository sarge Release
Get:8 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease [10.5 kB]
Get:9 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages [11.6 kB]
Get:10 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main arm64 Packages [3429 B]
Get:11 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main armhf Packages [3416 B]
Fetched 249 kB in 2s (126 kB/s)
Reading package lists... Done
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
--2022-05-09 16:55:45-- https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
Resolving packages.microsoft.com (packages.microsoft.com)... 104.214.230.139
Connecting to packages.microsoft.com (packages.microsoft.com)|104.214.230.139|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3692 (3.6K) [application/octet-stream]
Saving to: ‘packages-microsoft-prod.deb’
packages-microsoft-prod.deb 100%[=================================================>] 3.61K --.-KB/s in 0s
2022-05-09 16:55:45 (782 MB/s) - ‘packages-microsoft-prod.deb’ saved [3692/3692]
(Reading database ... 92411 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb ...
Unpacking packages-microsoft-prod (1.0-ubuntu22.04.1) over (1.0-ubuntu22.04.1) ...
Setting up packages-microsoft-prod (1.0-ubuntu22.04.1) ...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
apt-transport-https is already the newest version (2.4.5).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
Ign:4 https://download.webmin.com/download/repository sarge InRelease
Hit:5 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease
Hit:6 https://download.webmin.com/download/repository sarge Release
Hit:8 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 220 kB in 1s (283 kB/s)
Reading package lists... Done
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package dotnet-runtime-5.0
E: Couldn't find any package by glob 'dotnet-runtime-5.0'
E: Couldn't find any package by regex 'dotnet-runtime-5.0'
root:/tmp#