449

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 as you can see from the following command line result:

~$ bin/rcheck.sh
Reboot required.
~$ sudo shutdown -r now
shutdown: Unable to shutdown system
Louis Waweru
  • 25,409
  • 45
  • 137
  • 203

9 Answers9

684

You cannot reboot a distro with a single command. You must shut down and boot up the distro with two commands. If you run wsl.exe instead of wsl, then it works both in WSL Bash & CMD.

View the list of distros and their current state:

wsl.exe -l -v

Shutdown everything: Build 18917+

wsl.exe --shutdown

Terminate a specific distro: Windows 1903+

wsl.exe -t <DistroName>

Boot up the default distro (marked with *):

wsl.exe

Boot up a specific distro:

wsl.exe -d <DistroName>

Older versions

# PowerShell (admin)
Restart-Service LxssManager

or CMD (admin)

net stop LxssManager net start LxssManager

enter image description here

Sam Denty
  • 7,426
118

At an administrative PowerShell prompt: Restart-Service LxssManager

regexaurus
  • 1,299
41

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 '.*'
26

Just open a cmd window as adminstrator and run these commands to restart it.

net stop LxssManager
net start LxssManager
normarth
  • 385
15

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:

Create alias:

sudo nano ~/.bash_aliases

Add 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 --shutdown

or type

source .bash_aliases

Use

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.

Dara O h
  • 159
10

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:~$

Louis Waweru
  • 25,409
  • 45
  • 137
  • 203
3

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'/
...
llinfeng
  • 1,368
0

From inside the WSL/Ubuntu terminal, press Ctrl+D to shut down.

Restart ("reboot") the same way you started WSL the last time.

Henke
  • 1,261
0

If in any case wsl.exe --shutdown is hanging, you can run, in a PowerShell admin:

taskkill /f /im wslservice.exe