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 communityIs 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.
Shutdown everything: Build 18917+
wsl.exe --shutdown
Terminate specific distro: Windows 1903+
wsl.exe -t <DistroName>
# PowerShell (admin)
Restart-Service LxssManager
# or CMD (admin)
net stop LxssManager
net start LxssManager
net
worked in cmd (with admin). Just tested that my bat-file with sc
did not work in Windows OS Build 1809.
– llinfeng
Jan 15 '19 at 16:11
net
command is the legacy tool for managing Windows services and networks, pre-PowerShell
– Stabledog
Dec 7 '19 at 13:21
net
command (net stop LxxManager
seems to hang). Since I stay away from PowerShell (since I have WSL), the sc
command (query/stop/start) get the job done without any issues on that same Admin CMD window. I think it currently is the preferred API for the Service Control Manager?
– Flandraco
Apr 10 '20 at 0:45
At an administrative PowerShell prompt: Restart-Service LxssManager
WARNING: Waiting for service 'LxssManager (LxssManager)' to stop...
– Chris Snow
Jun 13 '19 at 15:53
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 '.*'
sudo touch /var/run/reboot-required
. In fact, it seems the presence of the file causes WSL to kill all background processes and shut down the subsystem when all terminal windows are closed, so you can abuse that as well.
– nyuszika7h
Jul 28 '18 at 8:40
killall
worked perfectly for me. Didn't need to touch reboot-required
.
– Giovanni Bassi
May 5 '19 at 16:06
Just open a cmd window as adminstrator and run these commands to restart it.
net stop LxssManager
net start LxssManager
timeout /t 3
command (add 3 seconds).
– Biswapriyo
Oct 21 '18 at 6:33
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).
Technically, 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.
Restart WSL
cmd.exe /C wsl --shutdown
or type
source .bash_aliases
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
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'/
...
net
was not working with my Windows 10 at the time? sc
must have worked back then. I should have specified the windows build number.
– llinfeng
Jan 2 '19 at 16:56
What I have done is:
wsl.exe --install
Then Windows will be updated accordingly. After that, the error gone. The Linux account can be created normally.