0


Ubuntu in WSL: Reboot Command is not working


I have been using WSL as a means to get access to Linux when developing software inside of the Windows 10: Pro Ed OS. But some of my preformated input lines that I use are not working because the reboot command doesn't seem to work when Ubuntu is running in the Windows Subsystem for Linux.

The preformatted input lines that I use are often executed using a bash variable that I assign the line to in the command line — i.e. $1, $2, $3. Usually though I create a Command-line Library (aka personal CLI for Linux navigation), which I will execute using a command that is supported through bin directory.


Here is an example of a traditional use case:

jay-dev@stack-overflow:~$ sudo apt update && sudo apt upgrade;sudo reboot;


Upon executing the $ sudo reboot command, Ubuntu prints the following:


    jay-dev@stack-overflow:~$ sudo reboot
    [sudo] password for andrew-chambers:
    System has not been booted with systemd as init system (PID 1). Can't operate.
    Failed to connect to bus: Host is down
    Failed to talk to init daemon.
    jay-dev@stack-overflow:~$

What I am trying to find out, is if there is a viable solution.

The following bullets are 3 examples of what a viable solution may look like:

  • A WSL Configuration that allows for the reboot command to execute successfully, which would mean, that reboot, reboots Ubuntu.

  • An alternative way of writing the reboot command, that will cause it to execute in a way that will result in Ubuntu Rebooting.

  • An alternative command altogether.

  • A way to write my own command that will reboot Ubuntu.


Closing & opening the terminal will not work, as I can't include that in any sort of preformatted way, or in any sort of code. (This much should be obvious)

JΛYDΞV
  • 678
  • 1
  • 10
  • 21
  • Your WSL setup does not support using `systemd` , therefore `reboot` will not work in any way. You can open a separate `cmd` Window and use `wsl --terminate`, but that won't really be useful in your situation. As far as I know you *can't* do it straight from WSL. – pigeonburger Aug 30 '21 at 22:35
  • I can corroborate the above. The only option in my Kali WSL machine only offers Logut (Restart and Shutdown are greyed out and cannot be used). So also does sudo reboot fail. – John Aug 30 '21 at 22:59
  • I can't remember where I saw it, but I'm fairly sure we solved this on a question on one of these Stack sites. It was pretty hacky, though. Running out the door at the moment, so can't find it right now. Also not quite sure it's needed - What services *in WSL* are you expecting need a full-on reboot after an `apt upgrade`? There probably are some, but I'm not sure off the top of my head. – NotTheDr01ds Aug 30 '21 at 23:09
  • The C++ compiler I just installed asked for me to enter the reboot command, which is how I ended up finding out that the reboot command didn't work. Background processes, or Daemons, require rebooting the terminal as well. Returning settings to the factory configuration requires a reboot. – JΛYDΞV Aug 30 '21 at 23:53
  • Its not that its super important, and its not that I am unable to close/open, its just that when I do close/open I loose my work environment, and as I stated above, I have little scripts I run here & there, and I have so many I can't remember all, but I know some use reboot, so when I use one its obviously not goin to work. – JΛYDΞV Aug 30 '21 at 23:53
  • Ah, [here it is](https://stackoverflow.com/a/67090137/11810933). A "shutdown" is easy, requiring a manual restart. A "reboot" is, as I said, pretty hacky. – NotTheDr01ds Aug 31 '21 at 00:15
  • 1
    I am gonna dup this question, because its been asked here, & not only that, but I think the answers here are the best solutions out there, though none of them are viable options for me. https://superuser.com/questions/1126721/rebooting-ubuntu-on-windows-without-rebooting-windows – JΛYDΞV Aug 31 '21 at 15:24
  • You would think that Microsoft could have done something along the way of... (see comment below) – JΛYDΞV Aug 31 '21 at 15:31
  • **`jay-dev@stackoverflow-com: ~/$`**_`wsl --restart ubuntu`_ – JΛYDΞV Aug 31 '21 at 15:32
  • @JAY-DEV Agreed, it would be a "nice-to-have", but given the "startup" of WSL is just typically opening a new tab in Windows Terminal (or equivalent), the `wsl --terminate ` is probably "good enough". Also, as I think about it, implementation on the Microsoft end probably isn't quite that "easy", since it's the controlling console/terminal that is responsible for "calling" `wsl.exe` (which starts it up). And WSL itself doesn't have any way to tell the owning terminal to restart it after a `wsl --shutdown` or `wsl --terminate`). – NotTheDr01ds Sep 02 '21 at 22:30

1 Answers1

3

You can reboot Ubuntu using the following command:

powershell.exe Restart-Service LxssManager

The caveat is that you need the shell running with Windows admin privileges.

Another way is wsl.exe --shutdown or wsl.exe -t <DistroName>. All these should work within WSL.

Aenfa
  • 511
  • 4
  • 12
  • Technically, that's a "shutdown" of the WSL instance itself rather than a "reboot". In other words, the WSL instance won't be running after any of those commands are executed. – NotTheDr01ds Aug 31 '21 at 00:10