Skip to content

Instantly share code, notes, and snippets.

@rbreaves
Forked from djfdyuruiry/README.md
Last active September 30, 2022 23:32
Show Gist options
  • Save rbreaves/24df597cb4cefc3f212d587666e4d3aa to your computer and use it in GitHub Desktop.
Save rbreaves/24df597cb4cefc3f212d587666e4d3aa to your computer and use it in GitHub Desktop.
WSL 2 - Enabling systemd

Enable systemd in WSL 2

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 called systemd-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/rbreaves/24df597cb4cefc3f212d587666e4d3aa/raw/48b3519f5be1fd5bdf58f359703b77ee31523185/install-sg.sh"
  • Make it executable:

    chmod +x /tmp/install-sg.sh
  • Run the new script:

    /tmp/install-sg.sh
    # genie requires this to change from graphics to multi-user
    sudo systemctl set-default multi-user.target
    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
#! /usr/bin/env bash
set -e
# change these if you want
UBUNTU_VERSION="22.04"
GENIE_VERSION="2.3"
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/ubuntu/${UBUNTU_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-6.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
@rbreaves
Copy link
Author

Hmmm :/.. well it worked for me, but am seeing that docker still seems broken..

@rrepka10
Copy link

Works for me, after I applied a few patches identified in genie/wiki/Systemd-units-known-to-be-problematic-under-WSL. Could you please publish a license or add a license script comments? e.g. unlicense.org

@rbreaves
Copy link
Author

At this point Microsoft has publicly announced official support for Systemd in wsl2 moving forward, so I do not believe these hacks are needed any longer and the license was whatever the guy determined that it ought to be that I forked it from lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment