Millions of developers across the globe are using Linux through WSL on Windows machines. It facilitates running both Linux and Windows in the same environment without any need to dual-boot a system. The good thing about WSL is that you can use multiple Linux distributions in it. Installing and managing them is also not difficult at all. In this guide, we’ll learn how to manage these distributions and how to switch between them. Basic troubleshooting of WSL Linux distro management is also included in this tutorial. So, let’s get started and run our favorite Linux distros in WSL. A mid-range PC/laptop is all you need to run it.
WSL uses a lightweight virtual machine, which enables it to run seamlessly alongside Windows. I'd recommend at least 8 GB of RAM for smooth functioning of WSL. And a dual-core or above processor.
Prerequisites for Running WSL
Before moving ahead, make sure you fulfill the following criteria:
- Windows 10 (Build 19041 or later), or Windows 11
- Admin account access on the Windows machine
- Enough free disk space
- Virtualization activated in BIOS/UEFI
If WSL is currently not installed, open PowerShell as administrator and use the following command:
wsl --install
By default, Ubuntu will be installed on top of WSL 2. Later, you can add more distributions.
Installing Multiple Linux Distributions
If you want to install additional Linux distributions in WSL, the process is fairly simple.
Step 1: Checking Available Distros
wsl --list --online
# Shorthand version
wsl -l -o
You may get output more or less similar to this:
This list will change over time as more distributions get added to the list.
Step 2: Installing a Specific Distribution
wsl --install -d <Distro Name>
# Example
wsl --install -d Debian
You can replace Debian with the distro name you want to install. For example, kali-linux.
If the installation process gets stuck at 0%, use the --web-download flag.
wsl --install --web-download -d Debian
Step 3: Set up User Account
After installation, when the distro is launched for the first time, it'll ask you for a username and password. I'd recommend setting up the same credentials you've used for your Windows account so that you can remember it easily.
Step 4: Confirm the Installation
Once the installation is complete, confirm if through the following command:
wsl --list --verbose
# Shorthand version
wsl -l -v
This command lists all the currently installed distros. The associated WSL version is shown in the last column. The asterisk (*) symbol denotes the default distro that'll be launched upon WSL startup.
Step 5: Repeat to Install More Distros
If you want to install additional distros, simply repeat these steps, changing the distro name in the command.
Managing Multiple Distros in WSL
Let's go through the set of commands we may need to manage Linux distributions daily.
| Command | Description |
|---|---|
wsl -l -v |
Display all the installed distros |
wsl -l --running |
List all the distros currently running |
wsl -d <Distro Name> |
Start or launch a specific distro |
wsl -d <Distro Name> -- <command> |
Execute a command within a specific distro |
wsl --set-default <Distro Name> |
Set a specific distro as the default one |
wsl --terminate <Distro Name> |
Stop the currently running specific distro |
wsl --shutdown |
Stop and close the WSL virtual machine |
wsl --unregister <Distro Name> |
Completely remove a specific distro |
wsl --update |
Update the WSL system |
Clone, Backup, and Import/Export Distros
A powerful feature of WSL is to let you export a distro, which you can later import at will. This export process is more or less like taking a snapshot of the entire filesystem.
Taking a Distro Backup
wsl --export kali-linux F:\Backups\kali-linux.tar
This command creates an archive that has all the WSL config files, filesystem image, and all the necessary data for that specific distro.
Cloning a Distro
If you are experimenting with something and don’t want to poison the current setup of your distro, you can clone and import it under a new name. It'll act as a sandbox with all the settings of your primary distro. After use you can delete this cloned distro.
wsl --export kali-linux F:\Backups\kali-linux.tar
wsl --import kali-linux-sandbox E:\WSL\kali-linux-sandbox F:\Backups\kali-linux.tar
Now, running wsl -d kali-linux-sandbox will launch this new cloned copy of the distro.
Moving Distro to a New Location
Let's say the drive where all your WSL distros reside is running out of space and you want to transfer one of the distros to a new drive. Here's how to do it:
wsl --terminate kali-linux
wsl --export kali-linux F:\Backups\kali-linux-backup.tar
wsl --unregister kali-linux
wsl --import kali-linux G:\WSL\kali-linux F:\Backups\kali-linux-backup.tar
To make sure the distro uses the same account you created earlier when installing it for the first time, use the following command.
kali-linux.exe config --default-user your-username
Skipping this step will set root as the default user for the moved distro.
Resource Usage Configuration via .wslconfig
There's a global .wslconfig file that can be used to configure the system resources (CPU, RAM, disk) WSL can use. Configuration in this file affects the entire WSL system, including every installed distro.
This file resides at %UserProfile%\.wslconfig. For example, C:\Users\rajeev\.wslconfig.
Here's a sample template you may start with:
[wsl2]
memory=8GB
processors=4
swap=2GB
localhostForwarding=true
# Modern networking mode
networkingMode=mirrored
dnsTunneling=true
firewall=true
[experimental]
autoMemoryReclaim=gradual
sparseVhd=true
Here's what each of these directives/attributes mean:
| Setting | Description |
|---|---|
memory |
Maximum amount of RAM WSL can use |
processors |
Number of vCPUs WSL can use |
swap |
Size of the swap file for WSL |
localhostForwarding |
Enables access to WSL services via Windows localhost |
networkingMode |
Windows network interfaces are mirrored into WSL |
autoMemoryReclaim |
Releases unused memory back to Windows |
sparseVhd |
Keeps the size of the virtual disk in check |
Remember, these settings do not apply automatically. First, you need to shut down the WSL system.
wsl --shutdown
Thereafter, launch wsl -d Ubuntu any distro for the new settings to take effect.
Configure Per-Distro Settings via wsl.conf
If you want to configure per-distro settings, edit the /etc/wsl.conf file. Here's a sample configuration you can tweak and edit as per your needs.
[boot]
systemd=true
[user]
default=rajeev
[automount]
enabled=true
options="metadata,umask=0077,fmask=0022"
[interop]
enabled=true
appendWindowsPath=true
The following is the explanation of every directive included above:
systemd=true- Enablessystemdfor the distro. Several modern services (e.g., Docker) need a Linux init system to function.[user] default=- Specifies which user is logged in with upon distro launch.[automount]- Governs which Windows drives are automatically mounted inside WSL and with what permissions.[interop]- Dictates if you can run Windows executables (e.g.,notepad.exe) right within the WSL environment.
For these settings to take effect, one must restart the distro.
wsl --terminate kali-linux
wsl -d kali-linux
After the restart, it takes a few seconds for the changes to take effect.
Best Practices for Managing Multi-Distro WSL Environment
Finally, here is a checklist to help you better manage multiple distributions in WSL.
- Do not install unnecessary distros. It only creates bloat.
- The most used distro should be set as the default to ensure it automatically launches whenever WSL starts.
- When exporting distros, always use a meaningful name with a date for the
.tarfile. - Always specify how much system resources WSL can use in the
.wslconfigfile. This ensures your Windows does not choke and works smoothly alongside WSL. - Only enable
systemdwithin the distro where you actually need it. - Make sure to run
wsl --updateevery month or so to keep your WSL instance up-to-date.
Conclusion
Managing multiple Linux distributions in WSL is easy due to a rich set of commands. Global and per-distro config files ensure you can fine-tune the environment as per your needs.
Only install distros you'll actually use.