379

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.

WSL. Reboot required. Unable to shutdown system

The screenshot text :

~$ bin/rcheck.sh
Reboot required.
~$ sudo shutdown -r now
shutdown: Unable to shutdown system
Henke
  • 813
  • 1
  • 8
  • 20
Louis Waweru
  • 23,945
  • 39
  • 132
  • 198
  • 1
    Rebooting (standard) WSL is not a thing. Simply put, a WSL distribution is just a container (like Docker) with a shell. Even with WSL 2, rebooting the VM does nothing to a distribution. – Daniel B Jun 02 '22 at 10:46

9 Answers9

556

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 -v

Shutdown everything: Build 18917+

wsl --shutdown

Terminate a specific distro: Windows 1903+

wsl -t <DistroName>

Boot up the default distro (marked with *):

wsl

Boot up a specific distro:

wsl -d <DistroName>

Older versions

# PowerShell (admin)
Restart-Service LxssManager

# or CMD (admin)
net stop LxssManager
net start LxssManager

enter image description here

ADTC
  • 2,954
  • 3
  • 30
  • 49
Sam Denty
  • 6,141
  • 3
  • 11
  • 16
  • 1
    why `net` instead of `sc`, as in @llinfeng's answer – Gaia Jan 01 '19 at 17:36
  • 1
    `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
  • 1
    @Gaia the `net` command is the legacy tool for managing Windows services and networks, pre-PowerShell – Stabledog Dec 07 '19 at 13:21
  • I had issues in an Admin CMD on my machine (Windows 10 build 17763) with the `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 00:45
  • 1
    I'm using the newest Windows Insider with WSL 2 and tried to use commands like `C:\Users\xxx>wsl -l -v` showing that three are "Ubuntu", "docker-desktop" and "docker-desktop-data" As in my case, there is also the newest docker running so wsl -shutdown works, but it also closes my docker environment After trial and error, I found that wsl -t "Ubuntu" works, but sometimes it takes time or is not reliable? Once it worked when I started command shell with admin rights. – Eino Mäkitalo May 14 '20 at 01:42
  • 2
    Working perfectly with `wsl2` ! – robe007 Jul 03 '20 at 19:46
  • That `-t` is not correct at all. At least when the OS needs reboot. When you terminate it with `-t` and run again, it will still need reboot... – Salda Jul 29 '20 at 18:21
  • Since there is no reboot, as a newbie, I had problems getting the newly installed Linux back on. – Jari Turkia Feb 09 '21 at 14:25
  • Is that a clean shutdown, like `shutdown -h`? IOW: if I have processes running, will they be given a chance to clean up? – Leo Apr 29 '21 at 06:26
  • If I do wsl.exe --shutdown, does that reboot Ubuntu, or merely shut it down? –  Feb 11 '22 at 18:42
  • I just tested it. This only shuts down Ubuntu - it does NOT reboot Ubuntu. The question asks for a way to REBOOT the system. If the only way to do this involves running "wsl --shutdown" and then manually booting up Ubuntu again, please indicate this in your answer. –  Feb 11 '22 at 18:44
109

At an administrative PowerShell prompt: Restart-Service LxssManager

regexaurus
  • 1,209
  • 1
  • 8
  • 2
  • 17
    @RajeshS It may be short but it does answer the question. – alexia Apr 21 '19 at 14:41
  • 1
    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 Waweru Apr 24 '19 at 01:43
  • 20
    I just get this repeatedly `WARNING: Waiting for service 'LxssManager (LxssManager)' to stop...` – Chris Snow Jun 13 '19 at 15:53
  • 5
    This works perfectly. Just start your powershell with admin rights first. – Erik Kalkoken Nov 01 '19 at 13:21
  • I have the same issue to Chris. – ー PupSoZeyDe ー Jun 04 '21 at 05:02
  • If you get a problem where you're waiting for the service to stop, you need to terminate the WSL VM first with ``wsl -d distro_name --shutdown`` and ``wsl -t distro_name``, then ``Restart-Service LxssManager`` should work properly. This is the "cleanest" solution, imo, that depends on Microsoft's tools to do the major work for you. – Robert Smith Sep 01 '22 at 12:52
  • this is the only method that works when WSLg is freezed and unresponsive, using `wsl --shutdown` is not enough. – francarl Sep 08 '22 at 13:09
39

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 '.*'
alexia
  • 2,577
  • 2
  • 22
  • 33
  • Do you know what I can do force a required reboot? I want to test the answer so I can accept it. – Louis Waweru Jun 10 '18 at 04:37
  • 1
    This worked for me. I had to `sudo`: `sudo killall -r '.*'` – F21 Jun 20 '18 at 09:19
  • 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. – alexia Jul 28 '18 at 08:40
  • 1
    `killall` worked perfectly for me. Didn't need to touch `reboot-required`. – Giovanni Bassi May 05 '19 at 16:06
  • Touching `reboot-required` (and closing all terminals) didn't do anything for me. In the end, I just did `wsl --shutdown` and `wsl -d ` (example: `wsl -d Ubuntu`; to get the list, use `wsl -l`). – ADTC Jun 10 '21 at 22:10
  • This is the only answer that seems to always work. The other answers here work *sometimes*, but not always. Note you still need to shut it down from Windows after running this command but this command gives Windows 10 control if it is lost. – NightOwl888 Jul 14 '22 at 10:34
25

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

net stop LxssManager
net start LxssManager
normarth
  • 367
  • 3
  • 2
  • 2
    Add some seconds between those two command. e.g. `timeout /t 3` command (add 3 seconds). – Biswapriyo Oct 21 '18 at 06:33
  • 2
    This duplicates samdd's answer from August. – fixer1234 Oct 25 '18 at 02:46
  • 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 Jun 05 '19 at 13:37
  • 3
    "The LxssManager service is stopping......................................................................... The LxssManager service could not be stopped." :-/ – Alex Jansen Nov 25 '19 at 23:26
12

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
  • 121
  • 1
  • 3
11

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
  • 23,945
  • 39
  • 132
  • 198
  • 11
    This does not work anymore. – Dakkaron Jul 24 '18 at 09:51
  • @Dakkaron - It did when the question was submitted. – Ramhound Oct 23 '18 at 01:55
  • 8
    That'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 Oct 23 '18 at 08:23
  • Specifically, it does not work since `Windows 10 Build 17046`. @Louis would you mind editing this into your answer? – Dakkaron Oct 23 '18 at 09:58
  • 1
    Works for me on build 17134. – Ian Kemp Nov 08 '18 at 07:19
  • 1
    Worked for me on 1909 (18363). So the answer is still valid. Make sure you run it in an elevated prompt. – Will I Am Feb 23 '20 at 01:01
  • @Dakkaron You're right, but one of the comments pointed out it will work in an elevated prompt, and I verified this before deciding to delete to leave this here. – Louis Waweru Dec 13 '20 at 08:16
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
  • 1,173
  • 2
  • 15
  • 36
  • why `sc` instead of `net`, as in @samdd's answer – Gaia Jan 01 '19 at 17:35
  • 1
    I 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 Jan 02 '19 at 16:56
1

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

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

Henke
  • 813
  • 1
  • 8
  • 20
  • Well, "sort of". The reality is much more complex. WSL will only actually "shut down" the controlling distribution and/or VM in certain scenarios. See [this answer](https://askubuntu.com/a/1436045/1165986) for the current status. Also see [this answer](https://askubuntu.com/a/1353286/1165986), where I give a similar answer to yours but with the caveats ;-). – NotTheDr01ds Oct 27 '22 at 17:11
-1

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.

Steven Lee
  • 99
  • 2
  • 2
    I'm not sure what you're trying to say, but this doesn't remotely answer the question. The OP already has WSL installed, and merely wanted a way to reboot the Linux subsystem without going through a full Windows reboot. – Auspex Sep 07 '22 at 09:34