Rebooting Ubuntu on Windows without rebooting Windows?

94

30

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.

Bash on Windows. Reboot required. shutdown: Unable to shutdown system

Louis

Posted 2016-09-21T13:49:15.893

Reputation: 18 859

Answers

117

Shutdown everything: Build 18917+

wsl --shutdown

Terminate specific distro: Windows 1903+

wsl -t <DistroName>

Older versions

# PowerShell (admin)
Restart-Service LxssManager

# CMD (admin)
net stop LxssManager
net start LxssManager

enter image description here

samdd

Posted 2016-09-21T13:49:15.893

Reputation: 1 616

why net instead of sc, as in @llinfeng's answer – Gaia – 2019-01-01T17:36:13.437

net worked in cmd (with admin). Just tested that my bat-file with sc did not work in Windows OS Build 1809. – llinfeng – 2019-01-15T16:11:50.053

@Gaia the net command is the legacy tool for managing Windows services and networks, pre-PowerShell – Stabledog – 2019-12-07T13:21:22.940

32

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

nyuszika7h

Posted 2016-09-21T13:49:15.893

Reputation: 2 024

Do you know what I can do force a required reboot? I want to test the answer so I can accept it. – Louis – 2018-06-10T04:37:29.557

1This worked for me. I had to sudo: sudo killall -r '.*' – F21 – 2018-06-20T09:19:48.447

1@Louis I see you've already accepted it, but you can do 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 – 2018-07-28T08:40:17.407

1killall worked perfectly for me. Didn't need to touch reboot-required. – Giovanni Bassi – 2019-05-05T16:06:26.413

27

At an administrative PowerShell prompt: Restart-Service LxssManager

regexaurus

Posted 2016-09-21T13:49:15.893

Reputation: 389

11@RajeshS It may be short but it does answer the question. – nyuszika7h – 2019-04-21T14:41:56.883

I like it. Easy to remember, autocompletes with tab well enough. Amusing to see how well Windows got its service model down right from the beginning. – Louis – 2019-04-24T01:43:21.760

3I just get this repeatedly WARNING: Waiting for service 'LxssManager (LxssManager)' to stop... – Chris Snow – 2019-06-13T15:53:48.783

This works perfectly. Just start your powershell with admin rights first. – Erik Kalkoken – 2019-11-01T13:21:49.107

10

Simply exiting the shell with exit and reopening seems to do the trick.

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

Posted 2016-09-21T13:49:15.893

Reputation: 18 859

5This does not work anymore. – Dakkaron – 2018-07-24T09:51:58.503

@Dakkaron - It did when the question was submitted. – Ramhound – 2018-10-23T01:55:32.670

2That's why I said "anymore". The information that this post is outdated is important, so other people who have the problem right now don't need to try it to find out that it does not work. I am not sure how things are handled here, but on Stackoverflow an answer is not only supposed to help the person who asked the question, but also all others who are looking for solutions for the same problem. – Dakkaron – 2018-10-23T08:23:27.327

Specifically, it does not work since Windows 10 Build 17046. @Louis would you mind editing this into your answer? – Dakkaron – 2018-10-23T09:58:12.333

Works for me on build 17134. – Ian Kemp – 2018-11-08T07:19:04.003

Worked for me on 1909 (18363). So the answer is still valid. Make sure you run it in an elevated prompt. – Will I Am – 2020-02-23T01:01:10.483

7

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

net stop LxssManager
net start LxssManager

normarth

Posted 2016-09-21T13:49:15.893

Reputation: 87

1Add some seconds between those two command. e.g. timeout /t 3 command (add 3 seconds). – Biswapriyo – 2018-10-21T06:33:33.177

2This duplicates samdd's answer from August. – fixer1234 – 2018-10-25T02:46:41.830

Doesn't work... stays in "stopping" status. when I try to run it again I get "The service is starting or stopping. Please try again later."... never finishes. Always hangs after I run an rsync command from batch like "bash -c 'rsync....'". This is a nightmare. – gunslingor – 2019-06-05T13:37:41.833

"The LxssManager service is stopping......................................................................... The LxssManager service could not be stopped." :-/ – Alex Jansen – 2019-11-25T23:26:46.037

4

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

Posted 2016-09-21T13:49:15.893

Reputation: 461

why sc instead of net, as in @samdd's answer – Gaia – 2019-01-01T17:35:48.507

1I guess 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 – 2019-01-02T16:56:04.000