Is it possible to reboot the Ubuntu sub-system without restarting my system?
I tried to use the
shutdown command after installing some updates, but that doesn't seem to be an option here.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Since Windows 10 version 1803, closing all WSL terminal windows won't kill background processes by default, unless the file
/var/run/reboot-required is present. This file will be automatically created by apt on Ubuntu when an update requires a reboot, but if you want to manually reboot the subsystem, you can create the file yourself:
sudo touch /var/run/reboot-required
I haven't tested this on other distributions available in the Microsoft Store. An alternative solution is to kill all processes yourself:
sudo killall -r '.*'
Simply exiting the shell with
exit and reopening seems to do the trick. The shell needs to be run as admin.
Louis@ATHENA:~$ bin/rcheck.sh Reboot not necessary. Louis@ATHENA:~$ bin/update.sh [sudo] password for Louis: The following packages will be upgraded: libssl1.0.0 openssl 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libssl1.0.0 amd64 1.0.1f-1ubuntu2.21 [830 kB] Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main openssl amd64 1.0.1f-1ubuntu2.21 [489 kB] Setting up libssl1.0.0:amd64 (1.0.1f-1ubuntu2.21) ... Setting up openssl (1.0.1f-1ubuntu2.21) ... Del libssl1.0.0 1.0.1f-1ubuntu2.20 [830 kB] Del openssl 1.0.1f-1ubuntu2.20 [489 kB] Louis@ATHENA:~$ bin/rcheck.sh Reboot required. Louis@ATHENA:~$ exec bash -l Louis@ATHENA:~$ bin/rcheck.sh Reboot required. Louis@ATHENA:~$ exit Louis@ATHENA:~$ bin/rcheck.sh Reboot not necessary. Louis@ATHENA:~$
The following allows a shutdown from within WSL2 using the command
wslreboot (or any custom command).
wslshutdown would be more appropriate for the code below:
sudo nano ~/.bash_aliases
alias wslreboot='history -a && cmd.exe /C wsl --shutdown'
history -a ensures that the bash command history us saved before shutdown.
cmd.exe /C wsl --shutdown
now you can type
I'm thinking you could use a variation of the above to run a batch file with the lines:
wsl --shutdown wsl
for a proper restart.
I have created a
*.bat file, and running it does the rebooting within 10 seconds. (I am amazed by how fast things get reloaded. And, please advise if my approach will cause serious trouble in the long run.)
Put the following two lines in a
WSL_reboot.bat file, and run it every time you need to reboot the WSL on Windows 10.
net stop LxssManager net start LxssManager
Update note: per my recent "upgrade" of Windows OS, the Build 1809 does not like
sc command anymore.
Side note: one need to reboot the WSL "kernel" when he/she format a lettered-drive through Windows Explorer. Haven't quite solve the by-product, though, where
ls command will get the following error. Related-post-from-WSL@Github; Related-post-from-the-Stack. Will drop a link if I manage to solve the by-product bug.
ls: 'System Volume Information': Permission denied ... d--x--x--x 1 llinfeng llinfeng 512 Jan 15 11:00 'System Volume Information'/ ...