Run systemd on WSL2 Distro

According to MS official documentation for WSL, systemd support can be enabled for WSL version 0.67.6+.

The WSL blog states that systems running Windows Insiders build can upgrade to the latest WSL version by downloading the update from the Microsoft Store.

If you’re not running Windows Insider, you can still download the latest release from the WSL official git repo releases section.

For example, the following steps describe the procedure for enabling systemd on kali-linux for systems not running Windows Insider edition:

  • Ensure target WSL distro has latest updates applied
  • Check current version of WSL
  • If running version is <0.67.6, download the latest *.msixbundle update for WSL from official git repo releases section
  • Install the .msixbundle
  • After installation is complete, check to ensure WSL has been updated
  • Add the following to /etc/wsl.conf WSL distro
  • shutdown the distro
  • Check systemd is running

Procedure Enabling systemd for WSL version <0.67.6

Objectives

  • Enable systemd on WSL2 Kali Linux distro using the one-script variant of the systemd hack for WSL2, sourced from git repo : https://github.com/diddledani/one-script-wsl2-systemd
  • Although the steps outlined in this article were tested against Kali, the hack should work with other WSL2 distributions
  • Refer to the documentation within git repo for further details on supported distributions

Assumptions

  • The script was tested on Windows 11 Pro, version 21H2 using Kali Linux, downloaded from Microsoft Store

Preparing WSL2 Distro

To simplify script deployment, passwordless sudo access for the target distribution username will be enabled.

This can always be reverted after systemd has been enabled.

  • To enable passwordless sudo, edit /etc/sudoers
  • Append the following line, replacing kali with the default username associated with target WSL distro:
  • Save changes with Ctrl+S and exit using Ctrl+X.
  • Apply system updates

Running the systemd Hack Script

  • From a Windows terminal, launch a PowerShell Administrator session
  • Note that Desktop edition of Powershell is used, i.e. PSEdition: Desktop
    ▪ Refer to the documentation on alternatives
  • Once within the session, change to an appropriate directory for saving the required script (to be downloaded in subsequent steps)
  • Run the following to install the wsl PowerShell module
  • Confirm the name of the target WSL distro, where systemd is to be enabled
  • Confirm the default username for the target distro
  • Run the systemd hack script, substituting the values of distro name and default username as obtained from the previous steps
    ▪ For the below example, distro name: kali-linux and default username: kali) are used
    ▪ Also, note that debug option has been enabled to allow for isolation and debugging of each process/command triggered by the installation script
  • Respond with Y for subsequent prompts
  • If there are no errors, the script should complete with the following message
  • Reboot WSL2

Dealing with Errors during Script Execution

  • For any failures encountered, identify the cause and rerun the install script
  • For example, the following shows output of a failed run
  • After some troubleshooting, the cause is found to be a result of an attempt to create a symlink at a non-existent path, i.e.
  • To resolve the issue, logon to the WSL distro, and manually create the path
  • Attempt to rerun the installation script once again:
  • Continue responding Y to prompts, and if all goes well, the script should complete with the following message
  • Reboot WSL2

Confirming systemd is Running

  • Logon to the distro and check systemd is running

Troubleshooting systemd Services

  • Check if any systemd services have failed to launch and examine logs to detemine best approach for resolving
  • Returns that service systemd-sysusers.service failed to load
  • Display the service status by running
  • The following shows the error related to the service
  • Quick web search returns the following link, which discusses a workaround: https://github.com/arkane-systems/genie/issues/190
  • The workaround involves adding a “drop in”/override for the service systemd-sysusers.service
  • To include the override, run edit for the service definition
  • and add the following

to the override config file, as shown below:

  • Save changes and exit (ctrl+s followed by ctrl+x)
  • The override file should now have been created at /etc/systemd/system/systemd-sysusers.service.d/override.conf with the following contents:
  • Restart the systemd-sysusers.service service
  • Check its status for errors
  • This shows the service is now running successfully
  • Check for failed units

returns no failed services

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store