Instructions for running Debian sid with systemd on WSL2
-
Make sure you're running Windows 10 Build 19041+ (run
ver
) -
Enable the Windows Subsystem for Linux (reboot if needed):
# In an elevated PowerShell session Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
-
Follow the instructions on this page or install a Linux distro from the Microsoft Store (this is required for preparing a Debian sid WSL distro)
-
Download the latest Debian sid cloud image. Make sure to download the latest
.tar.xz
file for your processor architecture (ex.debian-sid-generic-amd64-daily-20200710-323.tar.xz
) -
Create a rootfs archive from the downloaded sid image:
# In WSL (assuming you're running Debian Linux) # Extract the disk image from the archive # Make sure tar and xz-tools are installed (ie. apt install tar xz-utils) tar xf debian-sid-generic-*.tar.xz # mount the Linux filesystem # make sure fdisk, grep, and gawk are installed (ie. apt install fdisk grep gawk) sector_size=$(/sbin/fdisk -l disk.raw | grep 'Sector size' | grep -Po '\K([0-9]+)(?= bytes$)') start=$(/sbin/fdisk -l disk.raw | grep 'Linux filesystem' | awk '{ print $2 }') offset=$(($start * $sector_size)) sudo mkdir -p /mnt/sid sudo mount -o loop,offset=$offset disk.raw /mnt/sid # Create a rootfs `tar.gz` archive sudo tar -C /mnt/sid -cpzf debian-sid.tar.gz . sudo chown $(id -un):$(id -gn) debian-sid.tar.gz
-
Open File Explorer, navigate to
\\wsl$\name-of-the-distro
, and move the rootfs archive file to a directory accessible to Windows -
Open a PowerShell prompt in the directory containing the rootfs archive and import it:
wsl --import debian-sid \path\to\the\directory\you\want\to\install\debian-sid\into debian-sid.tar.gz --version 2
-
Start a shell in Debian sid and run the following commands:
# Update the OS apt update apt full-upgrade -y # Make sure sudo is installed apt install sudo
-
Edit
/etc/adduser.conf
and setADD_EXTRA_GROUPS
to 1 -
Create a non-root (ie.
adduser YOUR_USERNAME
) -
Edit
/etc/wsl.conf
and make sure the following lines exist in the file:[user] default = YOUR_USERNAME
-
Restart WSL:
# In PowerShell wsl --shutdown wsl -d debian-sid
-
Remove unnecessary packages/files:
apt remove --purge 'grub-*' 'linux-image-*' rm -rf /boot/* rm -rf /lost+found
-
TODO: Adapt this
-
Create a file in
/etc/profile.d/wsl.sh
with the following contents:# Start or enter a PID namespace in WSL2 source /usr/sbin/start-systemd-namespace # TODO: move the following lines into a script and allow running it script without a password (ie. /etc/sudoers.d/...) sudo systemctl default sudo systemctl reset-failed
-
Mask the services with
not-found
state:TODO: do something with the output of the following command (possibly pipe to xargs systemctl mask) systemctl --plain --no-legend --no-pager --state=not-found --all | awk '{ print $1 }'
Hi @zhengliuer. Thanks for your comment but as I mentioned in the gist, WSL now supports systemd officially. This procedure is no longer needed. You want to install a fresh copy of Debian, and create a file in
/etc/wsl.conf
with the following contents:Please see this link for more information.