Shut Down WSL Running Linux Distributions

So you are running Linux inside Windows using WSL. And you are wondering how you can shut down the Linux distribution running in WSL.

You can surely try the shutdown command from within the Linux system running in WSL:

sudo shutdown now

You can also shut down Linux systems using WSL commands. It’s an excellent method if you have more than one distro running is WSL.

Shutdown Linux in WSL using Windows Terminal

In this method, I assume that the usual shutdown command doesn’t work in WSL Linux Systems.

First, open a terminal in windows. Here, I am using Windows 11 with an Ubuntu setup under WSL 2.

Shut Down WSL Running Linux Distributions
Open a Windows Terminal
💡
You can use the wsl command on a standard Windows terminal. The command is also accessible inside a running Linux distribution. Here, the name of the command is wsl.exe.

Now, you need to list what distros are installed and what are their status. To do this, enter:

wsl --list --verbose

OR

wsl -l -v
Shut Down WSL Running Linux Distributions
List Installed Distributions

Here, you can see that, I have one installed WSL Ubuntu, which is currently running.

Shutdown all running Linux distributions

There may be times, when you want to stop app the running WSL instances in one go.

In Powershell or Windows Terminal, use this command:

wsl --shutdown

This will shut down all sessions.

Also, you can perform the same function inside any running WSL Linux Distribution terminal. You just need to use wsl.exe instead of wsl, while working inside a distribution.

wsl.exe --shutdown
Shut Down WSL Running Linux Distributions
Shut Down All Running WSL Distributions

Once you run this command, all the running WSL distributions will be terminated. The WSL 2 lightweight utility virtual machine is also terminated. So it will be useful, if you want to restart the WSL 2 virtual machine environment.

Terminate a particular Linus distribution

To terminate a particular running WSL distribution, open a separate Windows terminal and run:

wsl --terminate <Distribution Name>

Here, the distribution name is the one you get, when you list all the installed WSL distributions using the wsl -l -v ⁣ command.

Shut Down WSL Running Linux Distributions
List WSL Distributions
wsl --terminate Ubuntu

Once executed, the specified Linux distribution will be terminated.

If you are inside another distribution, list all the WSL distros installed on your system using:

wsl.exe -l -v

Now, terminate the required distro using:

wsl.exe --terminate <Distribution name>
Shut Down WSL Running Linux Distributions
Shutting down a WSL Distribution from inside another

Conclusion

Some people just close the running Linux application but I don’t think that’s very graceful.

Also, like a Linux terminal, you can either use:

  • The logout command, to close that distro.
  • The exit command to quit that terminal running the Linux distro.
  • Or, press CTRL+D to do the same as exit command.

But the WSL way of shutting down Linux system has the added advantage of doing it for multiple Linux systems.

I hope it helps you.

Leave a Comment