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
WSLConfiguration that allows for therebootcommand to execute successfully, which would mean, thatreboot, reboots Ubuntu.An alternative way of writing the
rebootcommand, 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)
systemd, thereforerebootwill not work in any way. You can open a separatecmdWindow and usewsl --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:35apt upgrade? There probably are some, but I'm not sure off the top of my head. – NotTheDr01ds Aug 30 '21 at 23:09jay-dev@stackoverflow-com: ~/$wsl --restart ubuntu– JΛYDΞV Aug 31 '21 at 15:32wsl --terminate <distro>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 awsl --shutdownorwsl --terminate). – NotTheDr01ds Sep 02 '21 at 22:30