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.
8 Answers
You cannot reboot a distro with a single command. You must shut down and boot up the distro with two commands.
View the list of distros and their current state:
wsl -l -vShutdown everything: Build 18917+
wsl --shutdownTerminate a specific distro: Windows 1903+
wsl -t <DistroName>Boot up the default distro (marked with *):
wslBoot up a specific distro:
wsl -d <DistroName>Older versions
# PowerShell (admin)
Restart-Service LxssManager
# or CMD (admin)
net stop LxssManager
net start LxssManager 11 At an administrative PowerShell prompt: Restart-Service LxssManager
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-requiredI haven't tested this on other distributions available in the Microsoft Store. An alternative solution is to kill all processes yourself:
sudo killall -r '.*' 5 Just open a cmd window as adminstrator and run these commands to restart it.
net stop LxssManager
net start LxssManager 4 The following allows a shutdown from within WSL2 using the commandwslreboot (or any custom command).
Technically, wslshutdown would be more appropriate for the code below:
Create alias:
sudo nano ~/.bash_aliasesAdd line:
alias wslreboot='history -a && cmd.exe /C wsl --shutdown'history -a ensures that the bash command history us saved before shutdown.
Enable Alias:
Restart WSL
cmd.exe /C wsl --shutdownor type
source .bash_aliasesUse
now you can type
wslreboot to shutdown
I'm thinking you could use a variation of the above to run a batch file with the lines:
wsl --shutdown
wslfor a proper restart.
1Simply 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 trusty-updates/main libssl1.0.0 amd64 1.0.1f-1ubuntu2.21 [830 kB]
Get:2 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:~$ 7 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'/
... 2 What I have done is:
- Enter this command in the command line you've opened in Admin mode:
wsl.exe --install - Restart your machine
Then Windows will be updated accordingly. After that, the error gone. The Linux account can be created normally.