ubuntu-wsl2-systemd-script icon indicating copy to clipboard operation
ubuntu-wsl2-systemd-script copied to clipboard

Not working on WSL2 - Ubutnu 20.04

Open nadavwolfin opened this issue 5 years ago • 31 comments
trafficstars

This script broke my WSL2 Ubuntnu 20.04 environment! image

nadavwolfin avatar Aug 09 '20 18:08 nadavwolfin

Looks like daemonize wasn't found for some reason.

You should be able to log into WSL by typing "wsl -u root" in cmd or powershell. Check if daemonize is installed by typing "which daemonize". I assume you'll have no output (I have "/usr/bin/daemonize" for example). If you do have some output, please post it in a reply. You can either install daemonize or disable the startup script.

To install daemonize type: "sudo apt-get install daemonize" Do note however, that it's quite likely that the other things the script tried to install failed. You can run the script again in that case. Remember to sudo it.

If you want to disable the systemd start script, do the following: Enter in "nano /etc/bash.bashrc" Put a # on the start of the line that says "source /usr/sbin/start-systemd-namespace" To enable the systemd start script again, simply remove the newly added #

Xideta avatar Aug 10 '20 10:08 Xideta

I'm having this issue as well, could ZSH come into play with it not working?

davidtaylorjr avatar Aug 11 '20 15:08 davidtaylorjr

Not working on a clean install of Ubuntu 20.04 LTS

Fails with:

x@Test:~/ubuntu-wsl2-systemd-script$ systemctl System has not been booted with systemd as init system (PID 1). Can't operate.

Script execution output:

x@Test:~/ubuntu-wsl2-systemd-script$ uname -a
Linux Test 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

x@Test:~/ubuntu-wsl2-systemd-script$ bash ubuntu-wsl2-systemd-script.sh
Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
Selecting previously unselected package daemonize.
(Reading database ... 31877 files and directories currently installed.)
Preparing to unpack .../daemonize_1.7.8-1_amd64.deb ...
Unpacking daemonize (1.7.8-1) ...
Selecting previously unselected package fontconfig.
Preparing to unpack .../fontconfig_2.13.1-2ubuntu3_amd64.deb ...
Unpacking fontconfig (2.13.1-2ubuntu3) ...
Setting up fontconfig (2.13.1-2ubuntu3) ...
Regenerating fonts cache... done.
Setting up daemonize (1.7.8-1) ...
Processing triggers for man-db (2.9.1-1) ...
'\\wsl$\Ubuntu-20.04\home\x\ubuntu-wsl2-systemd-script'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

SUCCESS: Specified value was saved.
'\\wsl$\Ubuntu-20.04\home\x\ubuntu-wsl2-systemd-script'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

SUCCESS: Specified value was saved.
x@Test:~/ubuntu-wsl2-systemd-script$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

svpn avatar Aug 11 '20 16:08 svpn

Not working on a clean install of Ubuntu 20.04 LTS

Fails with:

x@Test:~/ubuntu-wsl2-systemd-script$ systemctl System has not been booted with systemd as init system (PID 1). Can't operate.

Script execution output:

x@Test:~/ubuntu-wsl2-systemd-script$ uname -a
Linux Test 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

x@Test:~/ubuntu-wsl2-systemd-script$ bash ubuntu-wsl2-systemd-script.sh
Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
Selecting previously unselected package daemonize.
(Reading database ... 31877 files and directories currently installed.)
Preparing to unpack .../daemonize_1.7.8-1_amd64.deb ...
Unpacking daemonize (1.7.8-1) ...
Selecting previously unselected package fontconfig.
Preparing to unpack .../fontconfig_2.13.1-2ubuntu3_amd64.deb ...
Unpacking fontconfig (2.13.1-2ubuntu3) ...
Setting up fontconfig (2.13.1-2ubuntu3) ...
Regenerating fonts cache... done.
Setting up daemonize (1.7.8-1) ...
Processing triggers for man-db (2.9.1-1) ...
'\\wsl$\Ubuntu-20.04\home\x\ubuntu-wsl2-systemd-script'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

SUCCESS: Specified value was saved.
'\\wsl$\Ubuntu-20.04\home\x\ubuntu-wsl2-systemd-script'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

SUCCESS: Specified value was saved.
x@Test:~/ubuntu-wsl2-systemd-script$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

Same error I get

davidtaylorjr avatar Aug 11 '20 16:08 davidtaylorjr

Same here. Even more, it leads to some other errors(like this https://github.com/DamionGans/ubuntu-wsl2-systemd-script/issues/39). The worst thing is that the uninstall script is not available. Only Ubuntu reinstallation helped me.

egracens avatar Aug 16 '20 19:08 egracens

Make sure after the script install you terminate the distro with wsl.exe -t Ubuntu-20.04. After reopening the terminal you should be able to see the output of snap version.

onomatopellan avatar Aug 26 '20 22:08 onomatopellan

A bit of en evil loop - I cannot get wsl running,

λ wsl
Cannot execute daemonize to start systemd.

in order to get daeminze - I'm back to were I started with apt not working:

root@EP_Win8:/mnt/c/tools/sd_script# sudo apt-get install daemonize
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  accountsservice apport-symptoms command-not-found-data gdisk gir1.2-glib-2.0 iso-codes
  libaccountsservice0 libdumbnet1 libgirepository-1.0-1 libllvm8 python-apt-common run-one
Use 'sudo apt autoremove' to remove them.
E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt 2>/dev/null || true: Success
E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt 2>/dev/null || true: Success

Any hope?

epogrebnyak avatar Aug 30 '20 08:08 epogrebnyak

It helped however to disable the script as @Xideta pointed.

enter wsl as wsl -u root, then:

If you want to disable the systemd start script, do the following: Enter in "nano /etc/bash.bashrc" Put a # on the start of the line that says "source /usr/sbin/start-systemd-namespace" To enable the systemd start script again, simply remove the newly added #

This was the 'uninstall' procedure, in my case.

epogrebnyak avatar Aug 30 '20 08:08 epogrebnyak

I have the same issue, but when logging in via wsl (wsl -u <user>), I get this:

Sleeping for 1 second to let systemd settle
nsenter: cannot open /proc/24/ns/cgroup: No such file or directory

I'm using WSL2 + Ubuntu18.04

Edit: Has anyone tried the script mentioned in this comment: https://github.com/systemd/systemd/issues/8036#issuecomment-682240966

pavitrakumar78 avatar Aug 31 '20 16:08 pavitrakumar78

same issue. Not working for me. Thanks for the effort.

JBPlinn avatar Sep 29 '20 08:09 JBPlinn

gnome-session was not workig for me, and then analizing the script, i ran sudo apt-get remove -yqq daemonize dbus-user-session fontconfig, what is the reverse what did done the script, and I started recieving this message: cannot execure daemonize for systemd.

So the script may be failing to install the packages on some users...

marticliment avatar Oct 05 '20 16:10 marticliment

I use WSL2 + Ubuntu20.04. Solve the error "Cannot execute daemonize to start systemd." like this:

wsl -u root enters the shell, then solve it by installing "apt-get install daemonize".

y8gao avatar Oct 30 '20 08:10 y8gao

systemctl System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: 主机关闭

kinglionsz avatar Nov 09 '20 03:11 kinglionsz

Same for me, exactl the same error like @svpn has. Was able to recover with wsl -u root in cmd. Turns out, daemonize wasn't installed. Disabling the script for now.

simonszu avatar Nov 13 '20 08:11 simonszu

This has left my WSL dead, it doesn't even work the trick it used to:

sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME

Error:


nsenter: failed to execute 2744: No such file or directory

[proceso terminado con el código 1]

How can I leave everything as it was?

Fixed by commented out the startup script and restarting Ubuntu

Put a # on the start of the line that says source /usr/sbin/start-systemd-namespace on /etc/bash.bashrc

chiqui3d avatar Mar 03 '21 00:03 chiqui3d

Ubuntu 18.04 via wsl 2

I ran into this issue and solved it by uninstalling daemonize. Reinstalling sudo apt install daemonize. Exiting wsl. Re-enter wsl. And made sure the daemonize command worked.

mswezey23 avatar Mar 04 '21 05:03 mswezey23

"wsl -u root did not work for me since the environmental variable pointed to /etc/bash.bashrc. I was able to access the my wsl instance via the windows using \wsl$ in file explorer. I removed source /usr/sbin/start-systemd-namespace from /etc/bash.bashrc with notepad. and the instance worked. I guess I could have removed the environment variable first. Nevertheless, my wsl2 instance is back working. I hope this helps someone. So don't destroy your machine.

ebelfer2020 avatar Apr 07 '21 17:04 ebelfer2020

"wsl -u root did not work for me since the environmental variable pointed to /etc/bash.bashrc. I was able to access the my wsl instance via the windows using \wsl$ in file explorer. I removed source /usr/sbin/start-systemd-namespace from /etc/bash.bashrc with notepad. and the instance worked. I guess I could have removed the environment variable first. Nevertheless, my wsl2 instance is back working. I hope this helps someone. So don't destroy your machine.

In powershell

wsl.exe -e bash --norc
sudo vi /etc/bash.bashrc

and comment line consist "source /usr/sbin/start-systemd-namespace".

andreykonenkov avatar May 09 '21 07:05 andreykonenkov

I got similar issue error as

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

My wsl2 Env are using zsh, wslg, ms insider for windows 10 I check wsl in sudo mode or daemonize but it wasn't related to my issue

I check this issue and it works to my wsl https://github.com/DamionGans/ubuntu-wsl2-systemd-script/issues/25#issue-649660338

  1. add source /usr/sbin/start-systemd-namespace in .zshrc
  2. source .zshrc

And work

DevRyu avatar May 11 '21 15:05 DevRyu

I solved it!

1: sudo vi /etc/bash.bashrc 2: commit to "source /usr/sbin/start-systemd-namespace"

lppgo avatar Jun 15 '21 13:06 lppgo

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

Each time I restart my wsl2 ubuntu 20.04 all snaps are broken , What s the fix actually ? thanks

nicohouillon avatar Aug 31 '21 23:08 nicohouillon

Hi, I was able to make systemd to start with the following corrections:

Problem 1: after installation daemonize is installed in /usr/bin/daemonize Correction: file: /usr/sbin/enter-systemd-namespace ... at line 10 /usr/sbin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target correct to: /usr/bin/daemonize ...

Problem 2 error: "command /usr/sbin/enter-systemd-namespace not found" Correction: file: /usr/sbin/enter-systemd-namespace make executable sudo chmod +x /usr/sbin/enter-systemd-namespace

fredcamargo avatar Oct 17 '21 19:10 fredcamargo

Ubuntu 18.04 via wsl 2

I ran into this issue and solved it by uninstalling daemonize. Reinstalling sudo apt install daemonize. Exiting wsl. Re-enter wsl. And made sure the daemonize command worked.

I love you man :D

devbeno avatar Oct 17 '21 23:10 devbeno

Looks like daemonize wasn't found for some reason.

You should be able to log into WSL by typing "wsl -u root" in cmd or powershell. Check if daemonize is installed by typing "which daemonize". I assume you'll have no output (I have "/usr/bin/daemonize" for example). If you do have some output, please post it in a reply. You can either install daemonize or disable the startup script.

To install daemonize type: "sudo apt-get install daemonize" Do note however, that it's quite likely that the other things the script tried to install failed. You can run the script again in that case. Remember to sudo it.

If you want to disable the systemd start script, do the following: Enter in "nano /etc/bash.bashrc" Put a # on the start of the line that says "source /usr/sbin/start-systemd-namespace" To enable the systemd start script again, simply remove the newly added #

It works for me , thank you very much.

yunzhan2014 avatar Jan 08 '22 12:01 yunzhan2014

Thanks a lot! I thought i was going to reinstall the whole distro.

nicedfx avatar Feb 18 '22 18:02 nicedfx

Looks like daemonize wasn't found for some reason.

You should be able to log into WSL by typing "wsl -u root" in cmd or powershell. Check if daemonize is installed by typing "which daemonize". I assume you'll have no output (I have "/usr/bin/daemonize" for example). If you do have some output, please post it in a reply. You can either install daemonize or disable the startup script.

To install daemonize type: "sudo apt-get install daemonize" Do note however, that it's quite likely that the other things the script tried to install failed. You can run the script again in that case. Remember to sudo it.

If you want to disable the systemd start script, do the following: Enter in "nano /etc/bash.bashrc" Put a # on the start of the line that says "source /usr/sbin/start-systemd-namespace" To enable the systemd start script again, simply remove the newly added #

it saved me finally

GauravSinhaMM avatar Mar 31 '22 09:03 GauravSinhaMM

I using wsl2+ubuntu22.04. I also meet this problem and can not solve this with followed solutions:

sudo apt install daemonize

and

source /usr/sbin/start-systemd-namespace

because when i enter the wsl with

wsl -u root

and operate the following commands, the wsl2 feedback to me:

-sh: apt: not found
can't open '/usr/sbin/start-systemd-namespace': No such file or directory

and I enter the '/usr/bin', gauss what? there is no 'apt' inside it!!! what the hell !

Shawn-Tao avatar May 30 '22 12:05 Shawn-Tao

ohhh! I know everything! I enter the wsl belong to docker!

Shawn-Tao avatar May 30 '22 13:05 Shawn-Tao

so firstly, i just close the wsl by wsl.exe -t Ubuntu-20.04 and then open wsl by wsl -u root now it works image

cswangchen avatar Oct 28 '22 07:10 cswangchen

I use WSL2 + Ubuntu20.04. Solve the error "Cannot execute daemonize to start systemd." like this:

wsl -u root enters the shell, then solve it by installing "apt-get install daemonize".

This worked for me but only after i logged back in as usr and not logged in as root, which i found odd, but for what i'm doing right now i don't care.. just trying to get K3s installed for some fun with ansible/podman and automating custom execution environments. Thank you y8gao!!

systemd_hack

levelupjoseph avatar Dec 08 '22 05:12 levelupjoseph