DamionGans / ubuntu-wsl2-systemd-script

[Does not work anymore!] Script to enable systemd support on current Ubuntu WSL2 images
1.56k stars 383 forks source link

Not working on WSL2 - Ubutnu 20.04 #37

Open nadavwolfin opened 4 years ago

nadavwolfin commented 4 years ago

This script broke my WSL2 Ubuntnu 20.04 environment! image

Xideta commented 4 years ago

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 #

davidtaylorjr commented 4 years ago

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

svpn commented 4 years ago

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
davidtaylorjr commented 4 years ago

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

egracens commented 4 years ago

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.

onomatopellan commented 4 years ago

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.

epogrebnyak commented 4 years ago

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 commented 4 years ago

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.

pavitrakumar78 commented 4 years ago

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

JBPlinn commented 4 years ago

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

marticliment commented 4 years ago

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...

y8gao commented 3 years ago

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".

kinglionsz commented 3 years ago

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

simonszu commented 3 years ago

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.

chiqui3d commented 3 years ago

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

mswezey23 commented 3 years ago

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.

ebelfer2020 commented 3 years ago

"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.

andreykonenkov commented 3 years ago

"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".

DevRyu commented 3 years ago

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

lppgo commented 3 years ago

I solved it!

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

nicohouillon commented 3 years ago

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

fredcamargo commented 3 years ago

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

devbeno commented 3 years ago

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

yunzhan2014 commented 2 years ago

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.

nicedfx commented 2 years ago

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

GauravSinhaMM commented 2 years ago

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

Shawn-Tao commented 2 years ago

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 commented 2 years ago

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

cswangchen commented 1 year ago

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

levelupjoseph commented 1 year ago

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

felixxu06 commented 1 year ago

try to comment source /etc/bash.bashrc. Found the file is empty. image

Try to sudo apt install daemonize image Any one encounter this ?