This repository includes the files to set-up WSL2 distro to run systemd. This version is only compatible with Windows builds numbered 21286 and higher, which as of January 2021 are only available in the Dev channel of the Windows Insider program.
If you are using Windows Insider builds greater than 21286 you should use the build-21286+ branch
- Install a script that starts systemd inside a process namespace so that it gets PID 1.
- Install a sudoers configuration file that allows the script to call itself as root without requring setuid.
- Install GPG and SSH agent relays to Windows equivalents.
- Install WSLUtilities
- Configure your WSL sessions to connect to an X11 server in Windows.
- Configure xdg-open to open files and addresses in Windows
- Install GPG4Win via winget.exe, which is available in the latest dev branch of Windows 10 Insider Preview. (disable this with
-NoGPG) - Add a scheduled task that launches when you login to Windows to start the GPG-Agent from GPG4Win
- Install a custom WSL kernel based on the Microsoft sources with AppArmor added to support Snap Package strict confinement. (disable this with
-NoKernel) - Add a scheduled task that launches when you login to Windows to update the custom kernel when a new release is made.
- Enable and start the in-built Windows SSH-Agent service.
- Run
Install-Module -Scope CurrentUser Wslto install the required PowerShell module - Download the
install.ps1script - Open a PowerShell or CMD window: press
Win + xthen choose either "Command Prompt" or "Windows PowerShell" depending on which your system presents in the menu - Run the following command in the PowerShell Core or CMD window to set up your default distro (make sure to replace
powershell.exewithpwsh.exeif you're using PowerShell Core):pwsh.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -File \path\to\install.ps1
If you want to skip the GPG4Win installation, use the flag -NoGPG
You can also specify a distro name with the -distro flag, e.g:
pwsh.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -File \path\to\install.ps1 -distro Ubuntu-20.04You will find all the available distros on your system when executing wsl.exe --list --all in command prompt
Currently supported distros:
- Ubuntu
- Kali Linux
- Debian
- Alpine
- OpenSUSE
- Any other linux distribution with
apt-getorzypperas package manager
To manually install the bare-minimum setup, i.e. without using the PowerShell script, follow the procedure below:
- Edit or create the config file at
/etc/wsl.confto add the following content:[boot] command = "/usr/bin/env -i /usr/bin/unshare --fork --mount-proc --pid -- sh -c 'mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc; [ -x /usr/lib/systemd/systemd ] && exec /usr/lib/systemd/systemd --unit=multi-user.target || exec /lib/systemd/systemd'"
- Copy
src/sudoersto/etc/sudoers.d/wsl2-systemd. - Copy
src/00-wsl2-systemd.shto/etc/profile.d/00-wsl2-systemd.sh. - Exit any active terminal sessions that are using your distro.
- Use
wsl.exevia powershell to terminate/shutdown your distro so that thewsl.confsettings are applied.wsl.exe --terminate ubuntu
- Damion Gans' installer for the two-script variant
- Genie
- My 'change the user shell' variant that supports zsh and fish I do not keep the change the user shell variant updated so it is likely all sorts of broken.