DamionGans / ubuntu-wsl2-systemd-script

[Does not work anymore!] Script to enable systemd support on current Ubuntu WSL2 images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Script working, but very weird

haosmos opened this issue · comments

Hi everyone!

First of all, thanks for this script!

It works... but very weird for me)

My environment:

Windows 10
OS version: 2004
OS build: 20190.1000 (insider preview "dev")
WSL: Ubuntu-20.04.1
Linux kernel: 4.19.121

The script itself works strange: when I run wsl for the first time and execute a command:

snap version

The result of the command execution:

snap    2.45.1+20.04.2
snapd   unavailable
series  -

Then I execute the command:

systemctl

The result of the command execution:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

Then I execute the command:

sudo snap --list

The result of the command execution:

error: access denied (see 'snap help login')

Then I execute the command:

wslfetch

And, oh! miracle! Once this command is executed, snap packages become available.

But the weird thing doesn't end there - if I to run snap packets in a new session — an error will be displayed:

error: cannot find installed snap "bashtop" at revision 112: missing file /snap/bashtop/112/meta/snap.yaml

In addition, in the session where snap packages are available, are no longer commands available, such as: "code .zshrc" or "explorer.exe ."

code ~/.zshrc
zsh: command not found: code
explorer.exe .
zsh: command not found: explorer.exe

It seems that if systemd is available in the current session, which in turn makes snapd and snap packages available, this makes it impossible to use commands to run windows applications in this current session.

But if systemd is not available in the session, then application windows commands will be available.

And this is somehow affected by the command "wslfetch".

Obviously, if the error "zsh: command not found: code" or "zsh: command not found: code" is displayed, it is somehow related to the PATH environment variable.

It looks like that activation of systemd somehow modifies the PATH environment variable - but how? I don't understand that.

What result do I want to achieve? Ideally, for systemd to start with any new ubuntu session and this should not modify the PATH environment variable in any way - I should be able to use "code .something" or "explorer.exe ." and similar commands to run windows applications from ubuntu when systemd is activated.

This is a link to the video for a better understanding of the problem, where I show everything I wrote above: https://yadi.sk/i/gRPIMDwaDqt6uw

Same here

My Ubuntu-20.04 on 20H2 works perfectly until I do a machine reboot. Then I start hitting the errors you describe particularly things like "internal error, please report: running "microk8s" failed: cannot find installed snap "microk8s" at revision 1791: missing file /snap/microk8s/1791/meta/snap.yaml". Prior to the machine reboot, I get the "Sleeping for 1 second to let systemd settle" message when I open a new session. After the reboot this message does not appear. I've tried the --force option to no avail.

Not sure if this provides any further details or not.

same problem too.


I read the script, and found some configs were written into /etc/bash.bashrc.

then I copy following lines to /etc/zsh/zshrc. and it works

# Start or enter a PID namespace in WSL2
source /usr/sbin/start-systemd-namespace