Skip to content

Instantly share code, notes, and snippets.

@yasir2000
Forked from bnhf/README.md
Created April 13, 2022 20:30
Show Gist options
  • Save yasir2000/bd17c93fb8b54f34957f5fe1e0a7fa99 to your computer and use it in GitHub Desktop.
Save yasir2000/bd17c93fb8b54f34957f5fe1e0a7fa99 to your computer and use it in GitHub Desktop.
WSL 2 - Enabling systemd in Debian 11

Enable systemd in WSL2 Debian 11

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 called systemd-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
#! /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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment