Ubuntu in WSL: Reboot Command is not working [duplicate]
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 thereboot
command to execute successfully, which would mean, thatreboot
, 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)
Solution 1:
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.