This guide will help you install systemd
to run as normal under WSL2 Debian. This will allow services like microk8s
, docker
, cockpit
and many more to just work
during a WSL session. Note: this was tested on Windows 10 Build 21H2, running Debian 11 in WSL2.
- To enable
systemd
under WSL we require a tool calledsystemd-genie
- Download
install-sg.sh
to a temporary location/tmp
:
cd /tmp
sudo apt-get update && sudo apt-get install wget ca-certificates
wget --content-disposition \
"https://gist.githubusercontent.com/bnhf/ec85f1f91e3096f1499f995dd60b2097/raw/53a4f8e03b8c0073f4ddf17352cd157e4bba1b60/install-sg.sh"
- Make it executable:
sudo chmod +x install-sg.sh
- Run the script:
./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
Here’s the contents of the script you’d be downloading with the above wget command:
#! /usr/bin/env bash
set -e
# change these if you want
DEBIAN_VERSION="11"
GENIE_VERSION="2.2"
GENIE_FILE="systemd-genie_${GENIE_VERSION}_amd64"
GENIE_FILE_PATH="/tmp/${GENIE_FILE}.deb"
GENIE_DIR_PATH="/tmp/${GENIE_FILE}"
function installDebPackage() {
# install repackaged systemd-genie
sudo dpkg -i "${GENIE_FILE_PATH}"
rm -rf "${GENIE_FILE_PATH}"
}
function downloadDebPackage() {
rm -f "${GENIE_FILE_PATH}"
pushd /tmp
wget --content-disposition \
"https://github.com/arkane-systems/genie/releases/download/v${GENIE_VERSION}/systemd-genie_${GENIE_VERSION}_amd64.deb"
popd
}
function installDependencies() {
sudo apt-get update && sudo apt-get install apt-transport-https
wget --content-disposition \
"https://packages.microsoft.com/config/debian/${DEBIAN_VERSION}/packages-microsoft-prod.deb"
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y \
daemonize \
dotnet-runtime-5.0 \
systemd-container \
policykit-1 \
python3 \
python3-pip \
python3-psutil \
gawk
sudo rm -f /usr/sbin/daemonize
sudo ln -s /usr/bin/daemonize /usr/sbin/daemonize
}
function main() {
installDependencies
downloadDebPackage
installDebPackage
}
main
Credit to Matthew Snoddy (@djfdyuruiry on GitHub) for the original script written for WSL2 Ubuntu and a previous version of systemd-genie.