19

I'm a very first user of Ubuntu. I failed to install Ubuntu in wmware ,so I installed Ubuntu application in Microsoft app store and everything was quite all right. But when I insert shutdown or halt command to power off my ubuntu I kept getting 'system has not been booted with system as init system (PID 1). Can't operate' error message.

I tried to using docker following with this link (https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/) but I failed after going to Number 2 process many times. I'm not sure my failure is because of installing docker toll box instead of normal one. (my computer is just windows 10. not a windows pro)

I think I have to try other thing. If you don't mind me asking, how can I slove this problem?

(and one more. If I just click 'X' button at the top of right side, is it different with shutting down Ubuntu using 'halt' or 'shutdown' command?

Thank you

jamie 8910
  • 247
  • 1
  • 3
  • 10
  • 1
    To "shutdown" the WSL instance, this works: `$ exit` – bvj Feb 12 '19 at 23:02
  • @bvj using `exit` doesnt "shutdown" the WSL instance, it just closes the terminal. Run it again after using `exit` and loot at uptime in `htop`. – abmblob Jan 15 '20 at 21:59
  • @ABMRuman interesting observation. Possibility it's instead suspended on exit? – bvj Jan 16 '20 at 19:41
  • 1
    @bvj although I am not sure about this, but I believe the WSL is designed to run in the background like other windows processes. – abmblob Jan 17 '20 at 02:45

3 Answers3

28

I found this useful: https://linuxhandbook.com/system-has-not-been-booted-with-systemd/

In my case

# start docker using systemctl
sudo systemctl docker start 
# returns: 
# 
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

The basic advice is:

# check if your system is using `systemd` or `sysvinit`
ps -p 1 -o comm=

If the command doesn't return systemd, and in my case, Ubuntu-20.04 on WSL, the command returned init, then use the command pattern

# start services using sysvinit
service docker start

This works for me.

kingaj
  • 611
  • 6
  • 13
13

Based on this: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/

systemd is now available in WSL Version 0.67.6 or higher.

To enable:

Open a command prompt:

# CHOOSE option A or B:
# A. check your version and ensure it is 0.67.6 or higher
wsl.exe --version
# B. run WSL update if the version is low
wsl.exe --update

Open a WSL prompt:

sudo nano /etc/wsl.conf

Add this to wsl.conf and save the file:

[boot]
systemd=true

Go back to the command prompt:

# warning: this will kill any shells/processes you have running!
wsl.exe --shutdown
healthybodhi
  • 306
  • 2
  • 4
  • This answer worked for me. Technically, the selected answer would be correct. But, I really wanted to use systemd as that is what I am used to. Thanks for your answer! – Trevor Vance Dec 29 '22 at 15:12
4

First of all, Ubuntu installed via MS Store is using WSL (Windows Subsystem for Linux) Technology. It simply means there is no virtualization, Windows and Linux kernels are living side by side (the Linux kernel is not fully implemented yet).

So if you are trying to "shut down your Ubuntu", you would turn off the whole computer just like the Windows does. But in this case, WSL doesn't apparently have rights to do that.

In other words, you can look at your Ubuntu bash window just like any other terminal, like e.g. CMD or PowerShell.

When you start a program in the WSL (Ubuntu), you can see it also in Windows Task Manager - that's just a proof, that there is no virtualization.

Regarding docker: If I'm not mistaken Windows 10 Home doesn't provide Hyper-V virtualization. It means you'll have to use a different one e.g. by using VirtualBox. In order to make it work, I can recommend you to follow this tutorial and especially for VirtualBox please check this answer here

Hope it helps :)

DzeryCZ
  • 370
  • 3
  • 17