Home

Awesome

About

This repository includes the files to set-up WSL2 distro to run systemd.

What does it do

In WSL2

In Windows

Installing

  1. Run Install-Module -Scope CurrentUser Wsl to install the required PowerShell module
  2. Download the install.ps1 script
  3. Open a PowerShell or CMD window: press Win + x then choose either "Command Prompt" or "Windows PowerShell" depending on which your system presents in the menu
  4. Run the following command in the PowerShell Core or CMD window to set up your default distro (make sure to replace powershell.exe with pwsh.exe if 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.04

You will find all the available distros on your system when executing wsl.exe --list --all in command prompt

Currently supported distros:

Minimal manual installation

To manually install the bare-minimum setup, i.e. without using the PowerShell script, follow the procedure below:

  1. Edit or create the config file at /etc/wsl.conf to 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 --unit=multi-user.target'"
    
  2. Copy src/sudoers to /etc/sudoers.d/wsl2-systemd.
  3. Copy src/00-wsl2-systemd.sh to /etc/profile.d/00-wsl2-systemd.sh.
  4. Ensure that your user account is a member of the sudo group, or change %sudo in /etc/sudoers.d/wsl2-systemd to an alternative group name of which your account is a member.
  5. Exit any active terminal sessions that are using your distro.
  6. Use wsl.exe via powershell to terminate/shutdown your distro so that the wsl.conf settings are applied.
    wsl.exe --terminate ubuntu
    

Alternatives