Skip to content

Instantly share code, notes, and snippets.

@djfdyuruiry
Last active March 7, 2024 16:35
Show Gist options
  • Save djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950 to your computer and use it in GitHub Desktop.
Save djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950 to your computer and use it in GitHub Desktop.
WSL 2 - Enabling systemd

Enable systemd in WSL 2

NOTE: If you have Windows 11 there is now an official way to do this in WSL 2, use it if possible - see MS post here (WINDOWS 11 ONLY)

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/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh"
  • Make it executable:

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

    /tmp/install-sg.sh && 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="20.04"
GENIE_VERSION="1.44"
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
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 install apt-transport-https
sudo apt-get update
sudo apt-get install -y \
daemonize \
dotnet-runtime-5.0 \
systemd-container
sudo rm -f /usr/sbin/daemonize
sudo ln -s /usr/bin/daemonize /usr/sbin/daemonize
}
function main() {
installDependencies
downloadDebPackage
installDebPackage
}
main
@bnhf
Copy link

bnhf commented Mar 14, 2022

Where would one find these distro profiles? In the Windows file system somewhere? Debian file system? Via PowerShell?

I found the answer -- Windows Terminal, which is supposed to be available from the Microsoft Store, but isn't ATM. Works great for this purpose, plus allows for single window tabbed access to PS, Command, Azure and however many WSL distros you have installed. Downloadable from GitHub:

https://github.com/microsoft/terminal

@bnhf
Copy link

bnhf commented Mar 18, 2022

It's possible to use the above script with WSL2 Debian 11 -- but, I wouldn't recommend it. Too many differences in dependencies, plus this script adds Ubuntu repositories to sources.list -- which you need to reverse, or you won't be able to use apt. So, I went ahead and forked this Gist and modified it for Debian 11, plus updated genie to version 2.2. There's a new warning when you launch genie about default.target vs multiuser.target, but I believe the default is set to multi-user out-of-the-box. Check your sources.list to be sure you're on Debian 11 (Bullseye), and confirm that you have backports added. See the attached image for how it should look, and a proof-of-life for systemd running on WSL Debian 11. :-)

My fork of this Gist can be found @ https://gist.github.com/bnhf

image

@xuqingkuang
Copy link

The genie script break the WSLG XWindow System, I checked the system environment variable applied in the genie environment, but doesn't work.

WSLG works fine with startup normally.
wsl

But can't find display in the genie environment.
wsl-genie

@z404
Copy link

z404 commented Mar 29, 2022

I used this script here and I got to the part where it says "Waiting for systemd .....!!!!!!", now this will keep showing like this until you hit ctrl+c to shut down the command then run it again .. after which everything works fine.

Thanks a lot. this worked so well :D

@Nexxus-LMT
Copy link

Works with minimal debugging, caution and patience. At the time of writing default script runs well on WSL2 Ubuntu 20.04 three units that had to be masked or dealt with can be found on the previously linked page : https://github.com/arkane-systems/genie/wiki/Systemd-units-known-to-be-problematic-under-WSL .

On the first run before debugging the message " Waiting for systemd....!!!" seems to take ages however give it at least a minute before you panic. It will load and show all service/units that are causing a delay at boot. when you deal with them it reduces startup significantly.

Thanks to the OP and other for their input.

@RefriZaddo
Copy link

i wanna enable systemd but i use zsh in wsl2 how do i do it

@HeckTwrcha
Copy link

HeckTwrcha commented Apr 21, 2022

Add the required settings to the end of the "/.zshrc" file, which is equivelint to "/.bashrc" and "~/.bash_profile" in bash.

@ntman1
Copy link

ntman1 commented May 9, 2022

This does not work with Windows 10 Enterprise Edition (21H2) with WSL2 (Kernal v5.10.102.1) Ubuntu 22.04 LTS (Jammy Jellyfish) (see [https://apps.microsoft.com/store/detail/ubuntu-2204-lts/9PN20MSR04DW] for Microsoft Store distro)

I also modified install-sg.sh to change UBUNTU_VERSION="20.04" to UBUNTU_VERSION="22.04", with no avail. It also looks like arkane-systems/genie is now at Version 2.3, from the embedded version of 1.44 in the /tmp/install.sg.sh script.

root:/tmp# /tmp/install-sg.sh && rm /tmp/install-sg.sh
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:5 https://download.webmin.com/download/repository sarge InRelease
Hit:6 https://download.webmin.com/download/repository sarge Release
Get:8 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease [10.5 kB]
Get:9 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages [11.6 kB]
Get:10 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main arm64 Packages [3429 B]
Get:11 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main armhf Packages [3416 B]
Fetched 249 kB in 2s (126 kB/s)
Reading package lists... Done
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
--2022-05-09 16:55:45-- https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
Resolving packages.microsoft.com (packages.microsoft.com)... 104.214.230.139
Connecting to packages.microsoft.com (packages.microsoft.com)|104.214.230.139|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3692 (3.6K) [application/octet-stream]
Saving to: ‘packages-microsoft-prod.deb’

packages-microsoft-prod.deb 100%[=================================================>] 3.61K --.-KB/s in 0s

2022-05-09 16:55:45 (782 MB/s) - ‘packages-microsoft-prod.deb’ saved [3692/3692]

(Reading database ... 92411 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb ...
Unpacking packages-microsoft-prod (1.0-ubuntu22.04.1) over (1.0-ubuntu22.04.1) ...
Setting up packages-microsoft-prod (1.0-ubuntu22.04.1) ...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
apt-transport-https is already the newest version (2.4.5).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
Ign:4 https://download.webmin.com/download/repository sarge InRelease
Hit:5 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease
Hit:6 https://download.webmin.com/download/repository sarge Release
Hit:8 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 220 kB in 1s (283 kB/s)
Reading package lists... Done
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Packages (contrib/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target Translations (contrib/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
W: Target CNF (contrib/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:45 and /etc/apt/sources.list.d/archive_uri-http_download_webmin_com_download_repository-jammy.list:1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package dotnet-runtime-5.0
E: Couldn't find any package by glob 'dotnet-runtime-5.0'
E: Couldn't find any package by regex 'dotnet-runtime-5.0'
root:/tmp#

@bnhf
Copy link

bnhf commented May 10, 2022

This does not work with Windows 10 Enterprise Edition (21H2) with WSL2 (Kernal v5.10.102.1) Ubuntu 22.04 LTS (Jammy Jellyfish) (see [https://apps.microsoft.com/store/detail/ubuntu-2204-lts/9PN20MSR04DW] for Microsoft Store distro)

I did an updated version of this script for use with Debian 11. It might be of some help in determining script changes needed for the version of Ubuntu you want to use -- in addition to using a more recent version of the Genie project:

https://gist.github.com/bnhf/ec85f1f91e3096f1499f995dd60b2097

@bnhf
Copy link

bnhf commented May 10, 2022

E: Unable to locate package dotnet-runtime-5.0
E: Couldn't find any package by glob 'dotnet-runtime-5.0'
E: Couldn't find any package by regex 'dotnet-runtime-5.0'

I did some quick work on this for you, and the script below will run without error -- but it appears there may be issues with Ubuntu 22.04 and genie 2.3. On the initial launch I saw an endless number of exclamation marks, and on a subsequent attempt to launch genie, I got a warning about systemd being in a degraded state. I use Debian 11 myself, and the script I referenced in the previous post works great for that -- so I won't be investigating this any further. However, in the event you want to, here's the Ubuntu 22.04 modified version of my forked script:

#! /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

@fi0rini
Copy link

fi0rini commented May 11, 2022

I'm getting this error after following all the steps above

(base) PS C:\Users\name> wsl --status
Default Distribution: Debian
Default Version: 2

Windows Subsystem for Linux was last updated on 5/11/2022
The Windows Subsystem for Linux kernel can be manually updated with 'wsl --update', but automatic updates cannot occur due to your system settings.
To receive automatic kernel updates, please enable the Windows Update setting: 'Receive updates for other Microsoft products when you update Windows'.
For more information please visit https://aka.ms/wsl2kernel.

Kernel version: 5.10.102.1
(base) PS C:\Users\name> wsl --update
Checking for updates...
The Windows Subsystem for Linux kernel can be manually updated with 'wsl --update', but automatic updates cannot occur due to your system settings.
To receive automatic kernel updates, please enable the Windows Update setting: 'Receive updates for other Microsoft products when you update Windows'.
For more information please visit https://aka.ms/wsl2kernel.
(base) PS C:\Users\name> wsl genie -s
genie: error executing command 'daemonize /usr/bin/unshare -fp --propagation shared --mount-proc systemd':
No such file or directory

@bnhf
Copy link

bnhf commented May 11, 2022

Windows Subsystem for Linux was last updated on 5/11/2022
The Windows Subsystem for Linux kernel can be manually updated with 'wsl --update', but automatic updates cannot occur due to your system settings.
To receive automatic kernel updates, please enable the Windows Update setting: 'Receive updates for other Microsoft products when you update Windows'.
For more information please visit https://aka.ms/wsl2kernel.

The first error is probably related to your Windows Update settings, see:

https://winaero.com/how-to-install-linux-kernel-update-for-wsl-2-in-windows-10/

The second error could be because you said you followed the steps above which are for Ubuntu, and you're using Debian for your distro. I did a fork of this script for Debian (make sure you're on Debian 11 though using "cat /etc/issue" from a bash prompt):

https://gist.github.com/bnhf/ec85f1f91e3096f1499f995dd60b2097

@Sunchock
Copy link

@fi0rini

(base) PS C:\Users\name> wsl genie -s
genie: error executing command 'daemonize /usr/bin/unshare -fp --propagation shared --mount-proc systemd':
No such file or directory

I had the same issue before with Debian and also Ubuntu installed. My mistake was to had Debian as my default wsl system and i used this tutorial on Ubuntu as suggested. Setting Ubuntu as my new default WSL system solved my case.

You can also use : wsl -d <Distroname> genie -s and testing another wsl system.
I also recommand you to check for genie repository, you probably can find some useful informations in here : https://github.com/arkane-systems/genie

@Sneezy123
Copy link

I am still getting this after the installation (Ubuntu 20.04):

PS C:\Users\Petri> wsl --shutdown
PS C:\Users\Petri> wsl genie -s
/bin/sh: genie: not found

I have tried fresh installs with the directions in this readme and instructions https://github.com/arkane-systems/genie , as suggested above.

I also tried running PS with Admin privileges, but no prevail. However, if I type genie -s to the ubuntu terminal bash prompt, it works and I get to the bottle. I'm trying to get automatically to the bottle with Windows Terminal App, where you can launch wsl with command line parameters, and thus would like to get this working.

Did you run the install-sg.sh script (Step 3)?

@partisani
Copy link

partisani commented May 29, 2022

I'm getting errors in kali linux
there's some way to run it on kali linux? (wsl)

C:\Users\T440p>wsl --shutdown

C:\Users\T440p>wsl genie -s
/bin/bash: line 1: genie: command not found

C:\Users\T440p>

@Sneezy123
Copy link

I'm getting errors in kali linux there's some way to run it on kali linux? (wsl)

C:\Users\T440p>wsl --shutdown
C:\Users\T440p>wsl genie -s
/bin/bash: line 1: genie: command not found
C:\Users\T440p>

@IsaacPar look at the steps. You have to install genie in kali linux and then the command in Windows works

@HeckTwrcha
Copy link

Kali uses zsh as the default shell while the script is written for bash. So either run the scrip through bash or modify the script for zsh.

@rbreaves
Copy link

rbreaves commented Jun 13, 2022

it appears there may be issues with Ubuntu 22.04 and genie 2.3. On the initial launch I saw an endless number of exclamation marks, and on a subsequent attempt to launch genie, I got a warning about systemd being in a degraded state.

Thanks for that @bnhf, I left a comment on how to resolve it for 22.04, the guide at genie's repo was pretty accurate.

https://gist.github.com/rbreaves/24df597cb4cefc3f212d587666e4d3aa

@cyber-caveman
Copy link

Hi,
Tried the script and I'm getting the following 2 errors. Using Ubuntu 20.04 on WSL2 Kernel version: 5.10.16

Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Timed out waiting for systemd to enter running state.
This may indicate a systemd configuration error.
Attempting to continue.
Failed units will now be displayed (systemctl list-units --failed):
UNIT LOAD ACTIVE SUB DESCRIPTION
● systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems
● multipathd.socket loaded failed failed multipathd control socket

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

2 loaded units listed.

@kylhuk
Copy link

kylhuk commented Jun 16, 2022

Hi, Tried the script and I'm getting the following 2 errors. Using Ubuntu 20.04 on WSL2 Kernel version: 5.10.16

Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Timed out waiting for systemd to enter running state. This may indicate a systemd configuration error. Attempting to continue. Failed units will now be displayed (systemctl list-units --failed): UNIT LOAD ACTIVE SUB DESCRIPTION ● systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems ● multipathd.socket loaded failed failed multipathd control socket

LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

2 loaded units listed.

https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950?permalink_comment_id=3948284#gistcomment-3948284

@Daniel-W7
Copy link

感谢,完美解决了我的问题!
Thanks a lot for fixing my issues perfectly!

@HeckTwrcha
Copy link

Hi, The script depends on Microsoft Dotnet-sdk-5.0 that is replaced by Dotnet-sdk-6.0 (do not coexist). This is creating a dependency issue with the new distros or environments with Dotnet-sdk-6.0. Is it possible to update the script to support v6.0 or both? See the error below:

`Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
dotnet-runtime-deps-5.0 : Depends: libssl1.0.0 but it is not installable or
libssl1.0.2 but it is not installable or
libssl1.1 but it is not installable
systemd-container : Depends: systemd (= 249.11-0ubuntu3) but 249.11-0ubuntu3.3 is to be installed
Recommends: libnss-mymachines but it is not going to be installed
E: Unable to correct problems, you have held broken packages.`

@foxtr0
Copy link

foxtr0 commented Jul 5, 2022

So it did work, but now desktop environments are running too slow, i have no idea how to disable systemd, any tips?

@sunyihoo
Copy link

sunyihoo commented Aug 5, 2022

image
Is there any problem with this, or how to remove this warning? I use Genie version 2.4

@trbedwards
Copy link

@fi0rini

(base) PS C:\Users\name> wsl genie -s
genie: error executing command 'daemonize /usr/bin/unshare -fp --propagation shared --mount-proc systemd':
No such file or directory

I had the same issue before with Debian and also Ubuntu installed. My mistake was to had Debian as my default wsl system and i used this tutorial on Ubuntu as suggested. Setting Ubuntu as my new default WSL system solved my case.

You can also use : wsl -d <Distroname> genie -s and testing another wsl system. I also recommand you to check for genie repository, you probably can find some useful informations in here : https://github.com/arkane-systems/genie

I get the same error, even though Ubuntu is my default distro. I also explicitly chose ubuntu like so wsl -d Ubuntu-18.04 genie -s and the same thing happens

@manoj-bandara
Copy link

this didnt work for me. it went for a loop.

@tuxflo
Copy link

tuxflo commented Aug 12, 2022

Works on my machine (Default Ubuntu 20.04 setup), thanks a lot for providing the script and instructions.

@bryanSME
Copy link

bryanSME commented Aug 18, 2022

@djfdyuruiry you can replace the hard coded UBUNTU_VERSION and GENIE_VERSION with

UBUNTU_VERSION=`cat /etc/os-release | grep -Po 'VERSION_ID="\K.*?(?=")'`
GENIE_VERSION=`genie -V | grep -Po 'genie \K.+(?=)'`

@justdanpo
Copy link

Please replace url in README.md with one always linked to the latest version: https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/install-sg.sh

@simbamufasa
Copy link

It works, thanks. However, I'm running kali-linux rolling on wsl2, and once you have systemd using this method, running win-kex for desktop experience doesn't allow for audio support. All attempts to restart pulseaudio service return a "failed to connect to bus error", I tried export &(dbus-launch) and that led to another chain of erros. Does anyone know how to get pulseaudio back up again?

@simbamufasa
Copy link

It works, thanks. However, I'm running kali-linux rolling on wsl2, and once you have systemd using this method, running win-kex for desktop experience doesn't allow for audio support. All attempts to restart pulseaudio service return a "failed to connect to bus error", I tried export &(dbus-launch) and that led to another chain of erros. Does anyone know how to get pulseaudio back up again?

Meant export $(dbus-launch)

@Priyank-Solanki
Copy link

root@Mamma:/tmp# /tmp/install-sg.sh && rm /tmp/install-sg.sh
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists... Done
--2022-08-26 13:25:05--  https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
Resolving packages.microsoft.com (packages.microsoft.com)... 52.163.211.218, 40.90.4.1, 64.4.48.1, ...
Connecting to packages.microsoft.com (packages.microsoft.com)|52.163.211.218|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3690 (3.6K) [application/octet-stream]
Saving to: ‘packages-microsoft-prod.deb’

packages-microsoft-p 100%[====================>]   3.60K  --.-KB/s    in 0s

2022-08-26 13:25:06 (1005 MB/s) - ‘packages-microsoft-prod.deb’ saved [3690/3690]

Selecting previously unselected package packages-microsoft-prod.
(Reading database ... 34612 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb ...
Unpacking packages-microsoft-prod (1.0-ubuntu20.04.1) ...
Setting up packages-microsoft-prod (1.0-ubuntu20.04.1) ...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 17 not upgraded.
Need to get 1,512 B of archives.
After this operation, 169 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 apt-transport-https all 2.4.7 [1,512 B]
Fetched 1,512 B in 0s (5,307 B/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 34620 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.4.7_all.deb ...
Unpacking apt-transport-https (2.4.7) ...
Setting up apt-transport-https (2.4.7) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Failed to retrieve available kernel versions.

Failed to check for processor microcode upgrades.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Get:2 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease [10.5 kB]
Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:4 https://packages.microsoft.com/ubuntu/20.04/prod focal/main armhf Packages [24.8 kB]
Hit:5 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Get:6 https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages [187 kB]
Get:7 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 Packages [37.4 kB]
Hit:8 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 260 kB in 1s (233 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 dotnet-runtime-deps-5.0 : Depends: libssl1.0.0 but it is not installable or
                                    libssl1.0.2 but it is not installable or
                                    libssl1.1 but it is not installable
E: Unable to correct problems, you have held broken packages

Can anyone help me for the Ubuntu 22.04 version?

@HeckTwrcha
Copy link

It works, thanks. However, I'm running kali-linux rolling on wsl2, and once you have systemd using this method, running win-kex for desktop experience doesn't allow for audio support. All attempts to restart pulseaudio service return a "failed to connect to bus error", I tried export &(dbus-launch) and that led to another chain of erros. Does anyone know how to get pulseaudio back up again?

I guess this is an issue/bug with the 2022.3 Kali image not WSL or systemd issue. As I got the same issue with pulseaudio using the 2022.3_x64 kali-live iso image booting from a USB flash drive. I got a constant pulseaudio service crash message pop up the very first time the GUI initiated. This was out of the box behaviour. I did not troubleshoot it as I was not interested in the audio.

@HeckTwrcha
Copy link

root@Mamma:/tmp# /tmp/install-sg.sh && rm /tmp/install-sg.sh
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists... Done
--2022-08-26 13:25:05--  https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
Resolving packages.microsoft.com (packages.microsoft.com)... 52.163.211.218, 40.90.4.1, 64.4.48.1, ...
Connecting to packages.microsoft.com (packages.microsoft.com)|52.163.211.218|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3690 (3.6K) [application/octet-stream]
Saving to: ‘packages-microsoft-prod.deb’

packages-microsoft-p 100%[====================>]   3.60K  --.-KB/s    in 0s

2022-08-26 13:25:06 (1005 MB/s) - ‘packages-microsoft-prod.deb’ saved [3690/3690]

Selecting previously unselected package packages-microsoft-prod.
(Reading database ... 34612 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb ...
Unpacking packages-microsoft-prod (1.0-ubuntu20.04.1) ...
Setting up packages-microsoft-prod (1.0-ubuntu20.04.1) ...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 17 not upgraded.
Need to get 1,512 B of archives.
After this operation, 169 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 apt-transport-https all 2.4.7 [1,512 B]
Fetched 1,512 B in 0s (5,307 B/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 34620 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.4.7_all.deb ...
Unpacking apt-transport-https (2.4.7) ...
Setting up apt-transport-https (2.4.7) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Failed to retrieve available kernel versions.

Failed to check for processor microcode upgrades.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Get:2 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease [10.5 kB]
Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:4 https://packages.microsoft.com/ubuntu/20.04/prod focal/main armhf Packages [24.8 kB]
Hit:5 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Get:6 https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages [187 kB]
Get:7 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 Packages [37.4 kB]
Hit:8 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 260 kB in 1s (233 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 dotnet-runtime-deps-5.0 : Depends: libssl1.0.0 but it is not installable or
                                    libssl1.0.2 but it is not installable or
                                    libssl1.1 but it is not installable
E: Unable to correct problems, you have held broken packages

Can anyone help me for the Ubuntu 22.04 version?

After taking a look at the script, it is very simple, and you can change the dotnet-runtime version along with the distro version and genie version based on what you have or need. It simply downloads and installs the genie version specified, after installing all the dependances starting with packages-microsoft-prod.deb which will add Microsoft repository needed to fetch and install the required dotnet-runtime in addition to the other pre requisites (apt-transport-https, daemonize, systemd-container).

@ZhangPeng-Bobby
Copy link

ZhangPeng-Bobby commented Sep 7, 2022

bobby@NewBee:/mnt/c/WINDOWS/system32/tmp$ sudo apt install dotnet-runtime-5.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
dotnet-runtime-5.0 is already the newest version (5.0.17-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
bobby@NewBee:/mnt/c/WINDOWS/system32/tmp$ dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]
bobby@NewBee:/mnt/c/WINDOWS/system32/tmp$ genie
You must install or update .NET to run this application.

App: /usr/libexec/genie/genie
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '5.0.0' (x64)
.NET location: /usr/lib/dotnet/dotnet6-6.0.108

The following frameworks were found:
6.0.8 at [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]

Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x64&rid=ubuntu.22.04-x64

I followed the steps but got dotnet runtime error. If I only install runtime-5.0, my dotnet command broken because it said /usr/lib/dotnet/dotnet6-6.0.108 not exist. Can anyone help me on the dotnet runtime issue?

@HeckTwrcha
Copy link

Please edit the script before running it and change the dotnet runtime version from 5.0 to 6.0. Also make sure to set the latest genie version (v2.4) along with your distro name and version.

@LaurierSeguin
Copy link

C:\Users\lauri>wsl genie -s
Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Timed out waiting for systemd to enter running state.
This may indicate a systemd configuration error.
Attempting to continue.
Failed units will now be displayed (systemctl list-units --failed):
UNIT LOAD ACTIVE SUB DESCRIPTION
● ssh.service loaded failed failed OpenBSD Secure Shell server
● systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems
● multipathd.socket loaded failed failed multipathd control socket

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

3 loaded units listed.

laurier@GEEKOM-wsl:~$

@Neturo64
Copy link

help me.... when i run "wsl genie -s", i got error messege "Unknown command: genie"

@Slach
Copy link

Slach commented Sep 16, 2022

@bnhf thanks for 22.04 script, it works

@anttu-t
Copy link

anttu-t commented Sep 16, 2022

I would like to run a Windows program that loops until Ctrl+C as a systemd service, but when run as a service it quits immediately. (Systemctl status shows it loaded, inactive, exited with success)
I can run the Windows program OK on the command line and even in a shell script. I also tested my system file with service file exec start=sleep 60, and it stayed active OK.
What is the trick to keep also the windows program running until the service is stopped?

@HeckTwrcha
Copy link

Run the windows program in a separate shell to keep it running while you run commands in the 1st shell. Or run it as a service initiated at the system startup.

@anttu-t
Copy link

anttu-t commented Sep 16, 2022

Run the windows program in a separate shell to keep it running while you run commands in the 1st shell. Or run it as a service initiated at the system startup.

I need to run it as a service that a shell script can turn on and off.

Another option would be just to start and stop the program in the script, but I do not know how to send Ctrl+C to a Windows program from a Linux script.

@HeckTwrcha
Copy link

What script or programing language are you using? Any way, check this link:
https://stackoverflow.com/questions/64159363/how-to-handle-ctrl-c-in-shell-script

@anttu-t
Copy link

anttu-t commented Sep 17, 2022

What script or programing language are you using? Any way, check this link: https://stackoverflow.com/questions/64159363/how-to-handle-ctrl-c-in-shell-script

Shell script. Thanks for the link!

@yooakim
Copy link

yooakim commented Sep 22, 2022

@yangvanny
Copy link

image

PS C:\WINDOWS\system32> wsl genie -s
Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Timed out waiting for systemd to enter running state.
This may indicate a systemd configuration error.
Attempting to continue.
Failed units will now be displayed (systemctl list-units --failed):
UNIT LOAD ACTIVE SUB DESCRIPTION
● systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems
● multipathd.socket loaded failed failed multipathd control socket

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

2 loaded units listed.

bash: fg: no job control

@djfdyuruiry
Copy link
Author

And now systemd support is available from Microsoft/Canonical in WSL.

Thanks for this - updated gist

@tuxflo
Copy link

tuxflo commented Sep 25, 2022

Is there already a tutorial on how to migrate from the described setup of this gitst to the "officical way"?
Is it enough to just uninstall genie via apt?

@HeckTwrcha
Copy link

Just remove the geine -s from the ~/.bash_profile before upgrading wsl --upgrade to the latest kernel with systemd support. You don't have to uninstall genie. Enjoy

@tuxflo
Copy link

tuxflo commented Sep 26, 2022

Thanks! I will give it a try soon! 👍

@Steelwix
Copy link

Steelwix commented Sep 27, 2022

`PS C:\Users\Steelwix> wsl genie -s
Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Timed out waiting for systemd to enter running state.
This may indicate a systemd configuration error.
Attempting to continue.
Failed units will now be displayed (systemctl list-units --failed):
UNIT LOAD ACTIVE SUB DESCRIPTION
● multipathd.socket loaded failed failed multipathd control socket

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

1 loaded units listed.`

How to deal with the multipathd.socket fail?

@kylhuk
Copy link

kylhuk commented Sep 27, 2022

@Steelwix WSL now supports systemd, check a few comments above for infos

@voltrare
Copy link

@kylhuk not yet for windows 10 users and probably will take longer as wsl preview in store version only available on windows 11 sadly

@kylhuk
Copy link

kylhuk commented Sep 29, 2022

@kylhuk not yet for windows 10 users and probably will take longer as wsl preview in store version only available on windows 11 sadly

@voltrare Oh, I see - didn't know that was a thing. I kinda forgot why people do not want to upgrade to Windows 11 :)

@voltrare
Copy link

cuz lot of ppl actually still using old pcs that havent received win11 support tho im aware there is workaround but possibly itll be slower than win 10

@djfdyuruiry
Copy link
Author

djfdyuruiry commented Oct 8, 2022

Updated the gist guys as MS being silly about Windows 10 support

@mabusdogma
Copy link

C:\Users\me>wsl genie -s
genie: already inside the bottle; cannot start shell!

...alright, I've got the genie, how can I make it work?

@HeckTwrcha
Copy link

If you are on Win10, add 'genie -s' to your distro's ".bash_profile" then close and reopen your distro.
If you are on Win11 systemd is nativly supported and you do not need geine. Check the previous announcement made earlier in this thread.

@ringtailedfox
Copy link

ringtailedfox commented Oct 19, 2022

when i type wsl genie -s, i get this error:

genie: WARNING: systemd is in degraded state, issues may occur!
genie: already inside the bottle; cannot proceed

that can't be good...

edit:
i've found it's degraded becuase it can't find or start the two following services:
systemd-remount-fs.service.service
multipathd.socket.service

@chienbinhso14
Copy link

`PS C:\Users\Steelwix> wsl genie -s Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Timed out waiting for systemd to enter running state. This may indicate a systemd configuration error. Attempting to continue. Failed units will now be displayed (systemctl list-units --failed): UNIT LOAD ACTIVE SUB DESCRIPTION ● multipathd.socket loaded failed failed multipathd control socket

LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

1 loaded units listed.`

How to deal with the multipathd.socket fail?

Try to using Terminal on Windows App store and run it as Administrator

@voltrare
Copy link

you can refer to genie wiki for common problems
Systemd-units-known-to-be-problematic-under-WSL

@voltrare
Copy link

voltrare commented Oct 22, 2022

Try to using Terminal on Windows App store and run it as Administrator

nah man dont need to run as admin

@ringtailedfox
Copy link

I still have this issue:
genie: already inside the bottle; cannot proceed

i'm not sure what causes it...

@Mathiasb17
Copy link

Mathiasb17 commented Oct 27, 2022

I have Ubuntu 22.04 on WSL2 (Windows 10).

I reach the point where i type wsl genie -s, but nothing happens and the program returns after a few seconds :

C:\Users\mbrousse>wsl genie -s

C:\Users\mbrousse>

When i try to run genie in bash i get the following output :

$ genie
A fatal error occurred. The required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/usr/libexec/genie/].
If this is a framework-dependent application, install the runtime in the global location [/usr/lib/dotnet/dotnet6-6.0.110] or use the DOTNET_ROOT environment variable to specify the ru
ntime location or register the runtime location in [/etc/dotnet/install_location].

The .NET runtime can be found at:
  - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=ubuntu.22.04-x64&apphost_version=5.0.8

In the script i did update UBUNTU_VERSION to value 22.04.

Any lead on this ?

@4wk-
Copy link

4wk- commented Dec 19, 2022

Hello @djfdyuruiry I've encounter a dependency related issue.

dpkg: dependency problems prevent configuration of systemd-genie:
 systemd-genie depends on policykit-1; however:
  Package policykit-1 is not installed.
 systemd-genie depends on gawk; however:
  Package gawk is not installed.

In order to fix it:

apt --fix-broken install
dpkg-reconfigure systemd-genie

Fresh install of WSL on a fresh windows install. wsl --intall then reboot

wsl --set-default-version 2
wsl --install -d Debian
wsl --set-default Debian

Then, on Debian, I ran apt install wget (needed for your script) then as usual:

cd /tmp
wget --content-disposition \
"https://gist.githubusercontent.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh"

chmod +x /tmp/install-sg.sh
/tmp/install-sg.sh && rm /tmp/install-sg.sh

Then at the end, there is the dependencies issue:

dpkg: dependency problems prevent configuration of systemd-genie:
 systemd-genie depends on policykit-1; however:
  Package policykit-1 is not installed.
 systemd-genie depends on gawk; however:
  Package gawk is not installed.

@dominsights
Copy link

It didn't work for Ubuntu 22. I've used Ubuntu 20 and it worked fine.

@redlinejoes
Copy link

redlinejoes commented Dec 22, 2022

It didn't work for Ubuntu 22. I've used Ubuntu 20 and it worked fine.

This gist and the methods described are deprecated.

You should NOT be using this method any longer. The author needs to update this Gist to inform users that this is no longer necessary. WSL has been updated for Windows 10 to match what is available in Windows 11.

You should NOT be using this Gist or the methods described in this repo to enable systemd in WSL for Windows 10 or 11.

To enable the systemd support in Windows 10 or 11, you only need to update your WSL installation.

On Windows 10, when you run the WSL --version command, you should see the following:
WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.2364

On Windows 11, when you run the WSL --version command, you should see the following:
WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.25267.1000

If you run the latest version of WSL, you can enable the systemd support without issue in Ubuntu 22.04. So that you know, you will want to install WSL from the MS Store. Then you can enable the systemd support using the "/etc/wsl.conf" file with the following options:
[boot]
systemd=true

Follow these instructions for help. The procedure works on Windows 11; as of November 2022, it also works on Windows 10.
https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/

@4wk-
Copy link

4wk- commented Dec 27, 2022

@redlinejoes Thanks for the update... Yeah, this gist is saying "windows 11 ONLY" :/

I have the same wsl --version as you.
Now, I will try to clean and remove/uninstall everything this gist does: https://gist.githubusercontent.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh

@rrodrigueznt
Copy link

rrodrigueznt commented Jan 2, 2023

@4wk

I have the same wsl --version as you. Now, I will try to clean and remove/uninstall everything this gist does: https://gist.githubusercontent.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh

Please, have you managed to restore the original state of your WSL installation? How?

I followed the same procedure described in the original post above before @redlinejoes comment and end up with a WSL installation that pops up the following error message every time I launch my Ubuntu-20.04 Linux server:

popup

It doesn't happen if I launch my CentOS Stream 8 or 9 servers.

My WSL and Windows releases are:

PowerShell 7.3.1
PS C:\Users\ricar> wsl --version
WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.963
PS C:\Users\ricar>

Thanks!

@4wk-
Copy link

4wk- commented Jan 2, 2023

Hey @rrodrigueznt
I didn't find a clean way to restore the original state of my WSL installation.
So I did a complete uninstall then reinstall of wsl: https://gist.github.com/4wk-/889b26043f519259ab60386ca13ba91b

I had the same RemoteApp error as well.

Hope it helps!

@rrodrigueznt
Copy link

@4wk- Thanks!

I'm not able to understand how the script above affects the functioning of the whole WSL and not only to Ubuntu installation or installations (not sure if it affects only to a Debian installation existing before running the scrip or any other installed after running it). Please, do you or anybody does understand it? Thanks!

@4wk-
Copy link

4wk- commented Jan 3, 2023

@rrodrigueznt I don't understand all the ins and outs of the script above, that's why I wrote my own gist to properly uninstall then reinstall wsl.

But AFAIK, genie mod does not affect only debian, it affects all wsl install.

@rrodrigueznt
Copy link

rrodrigueznt commented Jan 3, 2023

@4wk- You wrote a nice guide to completely remove WSL and any distro on Windows. Thanks!
As I have here some four nice installations, Ubuntu and CentOS running under WSL2, I will try keeping removing Genie and get systemd working natively. In the WSL Genie site, there are packages to install it on different distros, that is why I'm guessing it must be possible to uninstall it. I will report here my failure or my success!

@rrodrigueznt
Copy link

@4wk-, all,

A first result: I have two running Ubuntu distros on the same WSL2 installation.

Ubuntu 22.04 is running smoothly and has systemd activated as per below:

rjr@IGFAE-MU-05-DellXPS-Windows10:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
rjr@IGFAE-MU-05-DellXPS-Windows10:~$ systemctl status logrotate.timer
● logrotate.timer - Daily rotation of log files
     Loaded: loaded (/lib/systemd/system/logrotate.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Wed 2023-01-04 08:27:58 CET; 3min 34s ago
    Trigger: Thu 2023-01-05 00:00:00 CET; 15h left
   Triggers: ● logrotate.service
       Docs: man:logrotate(8)
             man:logrotate.conf(5)

Jan 04 08:27:58 IGFAE-MU-05-DellXPS-Windows10 systemd[1]: Started Daily rotation of log files.
rjr@IGFAE-MU-05-DellXPS-Windows10:~$

Ubuntu 20.04 runs smoothly if I don't activate systemd:

ricardo@IGFAE-MU-05-DellXPS-Windows10:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
ricardo@IGFAE-MU-05-DellXPS-Windows10:~$ cat /etc/wsl.conf
#[boot]
#systemd=true
ricardo@IGFAE-MU-05-DellXPS-Windows10:~$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
ricardo@IGFAE-MU-05-DellXPS-Windows10:~$

But if troughs the aforementioned error The connection information for this resource is invalid when I launched it with systemd=true in ```/etc/wsl.conf````. Thus, I concluded so far that the WSL Genie issue relates with each installed distro, and it is possible to install fresh ones without need to remove the whole WSL2 thing. I will investigate further about the in troubles Ubuntu installation and keep this thread posted! Any comment is always welcome. Thanks.

@redlinejoes
Copy link

I get the impression that you guys intend to keep your WSL systems for some length of time. The whole idea of WSL and containers is that they can be deleted and recreated quickly and easily without fuss. If you intend to keep a Linux system, install a VM. The WSL installation can be easily broken by Windows updates or any random software you install, like Genie. It would be wiser to install a VM and perform a snapshot of the VM before you install system-altering software like Genie. This way, you can always revert.

If you dig deep enough, you can find ways to copy/export your WSL VHD for backup and recovery purposes or to move it to a different location, but it is an Internal Development Platform (IDP). It's not intended to be kept for any length of time on the system after you develop some software.

If your system doesn't work with systemd and Genie, it would be faster and easier just to delete the installation and reinstall WSL Ubuntu from MSStore using the latest version and enable systemd and do not return to this Gist since it has been deprecated now with the latest versions of WSL.

@rrodrigueznt
Copy link

@redlinejoes Got it! I will delete and forget my in-troubles Ubuntu 20.04 VHD. I can easily agree with your POV. Thanks!

@4wk-
Copy link

4wk- commented Jan 4, 2023

@redlinejoes I respectfully disagree: in my opinion, WSL is meant to be use for interoperability with Windows, which it does perfectly. Also, in my usage, WSL is a lot better that a VM performance-wise and convenient-wise. I use WSL to run docker containers when I need testing things "on the go", and delete/recreate containers. But my WSL daily use is, indeed, in the long term.

Be that as it may, your initial comment was just at the right moment as it taught me (and others probably) that wsl now support native systemD, which is great, and after cleaning wsl from genie, everything is working perfectly for me! So everything's fine 🙂

@redlinejoes
Copy link

Technically speaking, WSL is a VM. The main difference is the kernel. The kernel in WSL distributions is different because Microsoft develops it. Per Microsoft, it is intended to be used for interoperability during development. Everyone can read the docs here: https://learn.microsoft.com/en-us/windows/wsl/about.

During development on Windows, you absolutely should be using WSL for Docker. There is nothing to disagree with. What you describe are development purposes.

If someone intends to keep a heterogeneous Linux system for production, they should use the Linus-developed kernel distributions in a VM.

There are valid reasons why this is best practice from Microsoft and the Linux community and not a matter of opinion. Using the documentation from Microsoft, I'll go ahead and elaborate so others can know the differences.

From the documentation: https://learn.microsoft.com/en-us/windows/wsl/faq#who-is-wsl-for-
Who is WSL for?
"This is primarily a tool for developers, especially web developers, those working on open source projects, or deploying to Linux server environments. WSL is for anyone who likes using Bash, common Linux tools (sed, awk, etc.) and Linux-first frameworks (Ruby, Python, etc.) but also enjoys using Windows productivity tools."

From the documentation: https://learn.microsoft.com/en-us/windows/wsl/faq#can-i-use-wsl-for-production-scenarios--
Can I use WSL for production scenarios?
"WSL has been designed and built to use with inner loop development workflows. There are design features in WSL that make it great for this purpose but may make it challenging for production-related scenarios compared to other products. Our goal is to make clear how WSL differs from a regular VM environment, so you can make the decision on whether it fits your business needs."

The main differences between WSL and a traditional production environment are:

  • WSL has a lightweight utility VM that starts, stops and manages resources automatically.
  • If you have no open file handles to Windows processes, the WSL VM will automatically be shut down. This means if you are using it as a web server, SSH into it to run your server and then exit, the VM could shut down because it is detecting that users are finished using it and will clean up its resources.
  • WSL users have full access to their Linux instances. The lifetime of the VM, the registered WSL distributions, etc., are all accessible by the user and can be modified by the user.
  • WSL automatically gives file access to Windows files.
  • Windows paths are appended to your path by default, which could cause unexpected behavior for certain Linux applications compared to a traditional Linux environment.
  • WSL can run Windows executables from Linux, which could also lead to a different environment than a traditional Linux VM.
  • The Linux kernel used by WSL is updated automatically.
  • GPU access in WSL happens through a /dev/dxg device, which routes GPU calls out to the Windows GPU. This setup is different than a traditional Linux set up.
  • There are other smaller differences compared to bare metal Linux and more differences are expected to arise in the future as the inner loop development workflow is prioritized.

In summary, Microsoft is saying that WSL is not intended to replace running Linux as a VM, regardless of how WSL performs. WSL can do certain things that make it ideal for development workflows. However, it's been designed to operate differently than users expect from a typical Linux system. This makes it not ideal for production or long-running utilization. The confusion can stem from when a development tool is released to the public, and non-developers start to use it and think it's something it is not.

@4wk-
Copy link

4wk- commented Jan 7, 2023

So I misunderstood you earlier, sorry. I wasn't talking of production use. My use of WSL is only for developing purposes, and I do agree with you! Thanks!

@dominsights
Copy link

It didn't work for Ubuntu 22. I've used Ubuntu 20 and it worked fine.

This git and the methods described are deprecated.

You should NOT be using this method any longer. The author needs to update this Gist to inform users that this is no longer necessary. WSL has been updated for Windows 10 to match what is available in Windows 11.

You should NOT be using this Gist or the methods described in this repo to enable systemd in WSL for Windows 10 or 11.

To enable the systemd support in Windows 10 or 11, you only need to update your WSL installation.

On Windows 10, when you run the WSL --version command, you should see the following: WSL version: 1.0.3.0 Kernel version: 5.15.79.1 WSLg version: 1.0.47 MSRDC version: 1.2.3575 Direct3D version: 1.606.4 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.19045.2364

On Windows 11, when you run the WSL --version command, you should see the following: WSL version: 1.0.3.0 Kernel version: 5.15.79.1 WSLg version: 1.0.47 MSRDC version: 1.2.3575 Direct3D version: 1.606.4 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.25267.1000

If you run the latest version of WSL, you can enable the systemd support without issue in Ubuntu 22.04. So that you know, you will want to install WSL from the MS Store. Then you can enable the systemd support using the "/etc/wsl.conf" file with the following options: [boot] systemd=true

Follow these instructions for help. The procedure works on Windows 11; as of November 2022, it also works on Windows 10. https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/

It doesn't work on Windows 10. I have tried this multiple times, the only thing that worked was using the Ubuntu 20 and the method the author said above. Please don't remove the gist.

@dominsights
Copy link

Nevermind, I forked it.

@redlinejoes
Copy link

redlinejoes commented Jan 13, 2023

Please read the documentation for WSL upgrades.

Check your version of WSL on Windows 10 by using the following command:
wsl --version

If that command does not return WSL version: 1.0+, you do not have the correct version of WSL.

You can fork this Gist, but you'll still be using deprecated code and methods that are no longer supported and should not be used.

If you want support for WSL, we can help you.
What is the actual issue you are experiencing?
What exactly does not work on Windows 10?
What did you specifically try that failed?

Post the response to the wsl --version command and also check that you have properly configured systemd using the Microsoft supported and recommend method using "/etc/wsl.config"

@Guidoow
Copy link

Guidoow commented Mar 14, 2023

Works perfectly on Debian!
Thanks!

But there is a little problem when I do systemd

starting with PID 1 "init"
with and without being superuser:
Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.

starting with PID 1 systemd: (wsl genie -s)

Failed to create /user.slice/user-1000.slice/session-c3.scope/init.scope control group: Permission denied
Failed to allocate manager object: Permission denied

as super user:
Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.

About xdg_runtime_dir:
env | grep XDG_RUNTIME_DIR

XDG_RUNTIME_DIR=/run/user/1000

Any kind of help would be appreciated, im very new on linux, thanks!

Note that i do not need to execute systemd because systemctl actually works fine, I just want to solve this and know what is wrong. <3

@redlinejoes
Copy link

Works perfectly on Debian! Thanks!

But there is a little problem when I do systemd

starting with PID 1 "init" with and without being superuser: Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.

starting with PID 1 systemd: (wsl genie -s)

Failed to create /user.slice/user-1000.slice/session-c3.scope/init.scope control group: Permission denied
Failed to allocate manager object: Permission denied

as super user: Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.

About xdg_runtime_dir: env | grep XDG_RUNTIME_DIR

XDG_RUNTIME_DIR=/run/user/1000

Any kind of help would be appreciated, im very new on linux, thanks!

Note that i do not need to execute systemd because systemctl actually works fine, I just want to solve this and know what is wrong. <3

The procedure described in this gist has been out of date for over 4 months.
Nobody should follow this guide anymore. It's deprecated.
It should be removed from the Internet, so it stops people from following it.
Too many people come here, fail to read the comments and end up in your situation.
At this time, this gist is causing more harm than good.
It is especially concerning the amount of "very new to linux" users that stumble on this gist and have a bad experience with WSL or Linux in general.

@tuxflo
Copy link

tuxflo commented Mar 14, 2023

It may be worth mentioning, that the "updated way" of enabling systemd also works in Windows 10 (not just Windows 11 as stated in the header section of the gist).
I was using this method for a long time because I thought the official way is Windows 11 only and my company managed PC is not able to upgrade to Windows 11.
Just update WSL and follow the official docs on how to enable systemd.

@Mart-Bogdan
Copy link

Mart-Bogdan commented Mar 14, 2023

It may be worth mentioning, that the "updated way" of enabling systemd also works in Windows 10 (not just Windows 11 as stated in the header section of the gist).

Yeah. Thanks, @tuxflo. I can confirm that it works on Windows 10.0.19045.2604

But start up time is slower than raw WSL without systemd.

Option with genie allowed you to chose whether to launch systemd)

@Guidoow
Copy link

Guidoow commented Mar 14, 2023

The procedure described in this gist has been out of date for over 4 months. Nobody should follow this guide anymore. It's deprecated. It should be removed from the Internet, so it stops people from following it. Too many people come here, fail to read the comments and end up in your situation. At this time, this gist is causing more harm than good. It is especially concerning the amount of "very new to linux" users that stumble on this gist and have a bad experience with WSL or Linux in general.

I don't think so @redlinejoes, maybe you can explain more.
If "no one should use this guide", how can a WSL user use systemctl any other way? In my case, I couldn't use systemctl before (because PID 1 = init != systemd) and now I can with this script.
I just flagged a simple error with the systemd command and|or the configuration. I tried a few commands (including systemctl) that didn't work before, but now with this script, are perfectly working and solved some of my problems.

I found another method to start with systemd as PID 1 which is detailed here:
https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/
But it throws similar errors as this method, and some more like "Failed to connect to bus: No such file or directory" when tried to execute systemctl without super user.

There is any method that u recommend to solve this?

@tuxflo
Copy link

tuxflo commented Mar 14, 2023

But start up time is slower than raw WSL without systemd.

Well I guess you could simulate the switch between systemd and non systemd with a script that toggles the boolean value systemd = true in the wsl.conf but I'm happy with systemd at all time (since I had reasons for enabling it).

@Mart-Bogdan
Copy link

I found another method to start with systemd as PID 1 which is detailed here:
https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/
But it throws similar errors as this method, and some more like "Failed to connect to bus: No such file or directory" when tried to execute systemctl without super user.

@Guidoow did you run wsl --update ?

@Mart-Bogdan
Copy link

Well I guess you could simulate the switch between systemd and non systemd with a script that toggles the boolean value systemd = true in the wsl.conf but I'm happy with systemd at all time (since I had reasons for enabling it).

@tuxflo but you need to run WSL first, yes? Coz that file is inside /etc/wsl.conf, not on a host.

But that's fine, yes. Benefits are better, can wait few seconds :-)

@Guidoow
Copy link

Guidoow commented Mar 15, 2023

@Guidoow did you run wsl --update ?

@Mart-Bogdan yes, I did.
After WSL and Debian reinstallation and properly update, using this script, It is working PERFECT, Including the above error of systemd $XDG_RUNTIME_DIR. Thanks!

@redlinejoes
Copy link

I don't think so @redlinejoes, maybe you can explain more. If "no one should use this guide", how can a WSL user use systemctl any other way?

There is any method that u recommend to solve this?

You are operating with the assumption that the last six months of development didn't happen.

There is no reason for that when all the necessary information is included in this thread.

This leads one to believe you have yet to read and comprehend it.

The answer you seek is explained in detail in this thread. You must do yourself a favor and read my previous comment fully.
https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950?permalink_comment_id=4410998#gistcomment-4410998

There is no reason anyone should use the methods described in this guide. This Gist does more harm than good and is damaging to the open-source software community since the release of WSL version: 1.0.3.0.

@tertek
Copy link

tertek commented Jun 27, 2023

This is much easier in 2023, source: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/
Just ensure you have the latest version of WSL:

wsl --update
wsl --version
# soemthing like this
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.3086

Simply add within your distro, e.g. Ubuntu inside /etc/wsl.conf:

[boot]
systemd = true

@redlinejoes
Copy link

This is much easier in 2023, source: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/ Just ensure you have the latest version of WSL:

wsl --update
wsl --version
# soemthing like this
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.3086

Simply add within your distro, e.g. Ubuntu inside /etc/wsl.conf:

[boot]
systemd = true

It's been this way since 2022.
Read my reply from Dec 2022.
I copied the link here for you to make it easier for you to find and read.

https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950?permalink_comment_id=4410998#gistcomment-4410998

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