# Install Multiple Instances of WSL2 Linux on Windows 11
> Here's an easy method which allows you to install multiple instances of any Linux Distro in any location under WSL2.
** Click on each heading to reveal instructions **
If you HAVEN'T installed WSL2 prior to this, open up a Powershell terminal and execute the following commands:
```Powershell
PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName 'Containers' -All
PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Hyper-V' -All
PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform' -All
PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Windows-Subsystem-Linux' -All
```
The first thing you need to do is download a linux distro. This is a list of all distros released by Mocrosoft specifically for WSL2:
* [Ubuntu](https://aka.ms/wslubuntu)
* [Ubuntu 24.04](https://wslstorestorage.blob.core.windows.net/wslblob/Ubuntu2404-240425.AppxBundle)
* [Ubuntu 22.04 LTS](https://aka.ms/wslubuntu2204)
* [Ubuntu 20.04](https://aka.ms/wslubuntu2004)
* [Ubuntu 20.04 ARM](https://aka.ms/wslubuntu2004arm)
* [Ubuntu 18.04](https://aka.ms/wsl-ubuntu-1804)
* [Ubuntu 18.04 ARM](https://aka.ms/wsl-ubuntu-1804-arm)
* [Ubuntu 16.04](https://aka.ms/wsl-ubuntu-1604)
* [Debian GNU/Linux](https://aka.ms/wsl-debian-gnulinux)
* [Kali Linux](https://aka.ms/wsl-kali-linux-new) ([Win-Kex Install Docs](https://www.kali.org/docs/wsl/win-kex/))
* [SUSE Linux Enterprise Server 12](https://aka.ms/wsl-sles-12)
* [SUSE Linux Enterprise Server 15 SP2](https://aka.ms/wsl-SUSELinuxEnterpriseServer15SP2)
* [SUSE Linux Enterprise Server 15 SP3](https://aka.ms/wsl-SUSELinuxEnterpriseServer15SP3)
* [openSUSE Tumbleweed](https://aka.ms/wsl-opensuse-tumbleweed)
* [openSUSE Leap 15.3](https://aka.ms/wsl-opensuseleap15-3)
* [openSUSE Leap 15.2](https://aka.ms/wsl-opensuseleap15-2)
* [Oracle Linux 8.5](https://aka.ms/wsl-oraclelinux-8-5)
* [Oracle Linux 7.9](https://aka.ms/wsl-oraclelinux-7-9)
* [Fedora Remix for WSL](https://github.com/WhitewaterFoundry/WSLFedoraRemix/releases/)
(And if you're not already using it, install **Windows Terminal** from the Windows Store also - you won't regret it)
[`^ Top`](#download)
So, let's assume for a moment that your C: drive is dangerously low on space and you need to choose another location to install WSL2. Using Windows Explorer, grab the Linux distro you just downloaded from your downloads directory and copy it to wherever you're going to install it. For the purposes of this guide, I'm going to assume that you've downloaded **Ubuntu 22.04 LTS** and you're going to install into **E:\WSL**.
Open Windows Terminal to a Powershell prompt and execute the following commands to create your install location:
```powershell
PS C:\> E:
PS E:\> mkdir WSL
```
[`^ Top`](#locate)
Now, the first thing you need to do is rename the archive of the distro you downloaded so that it has a `.zip` extension:
```powershell
PS E:\> cd WSL
PS E:\WSL> mv Ubuntu2204-221101.AppxBundle Ubuntu-22.04.zip
```
Then, using Windows Explorer, double click on the distro archive, then select and extract the `_x64.appx` file as shown below:

Once you've extracted the installer, you don't actually need the archive you pulled it from any longer. You can delete it or stick it in your own file archives if you like - and you're going to need to change the extension on that `.appx` file as well (either using Windows Explorer or Powershell - up to you)

```powershell
PS E:\WSL> rm Ubuntu-22.04.zip
PS E:\WSL> mv Ubuntu_2204.1.7.0_x64.appx Ubuntu-22.04.zip
PS E:\WSL> Expand-Archive -Path Ubuntu-22.04.zip -DestinationPath E:\WSL\Ubuntu
```
The end result of which will be:

Then all you need to do is execute the `ubuntu.exe` file to install your first instance:
```powershell
PS E:\WSL> cd Ubuntu
PS E:\WSL\Ubuntu> .\ubuntu.exe
```
[`^ Top`](#install)
Now let's create your `BASE INSTANCE`.
Open either a simple Command Prompt or a Powershell Prompt and let's take care of a little housekeeping.
First, get a list of all WSL instances currently running on your machine:
```powershell
PS E:\WSL> wsl -l -v
```
It should look something like this:
```powershell
NAME STATE VERSION
* Ubuntu Running 2
```
(* Each instance will be named after its parent folder ... more on this later)
Hopefully you've installed **Windows Terminal** from the Windows Store - if not, you can open a new terminal window for any WSL instance using this command:
`wsl -d `
```powershell
PS E:\WSL> wsl -d Ubuntu
```
#### Step 1 - Set Password for Root User
This first step is not necessarily based on best practices, but I've always found it to be useful. Skip this step if you want to:
````shell
user@WSL: /$ sudo passwd root
````
#### Step 2 - Update & Upgrade
Next you want to make sure you've got the latest version of everything installed:
```shell
user@WSL: /$ sudo apt update && sudo apt upgrade -y
```
If you've installed an Ubuntu LTS release, you're also going to want to make sure you've got the latest kernel updates:
```shell
user@WSL: /$ sudo do-release-upgrade
```
In any case, you'll want to make sure to clean up after yourself:
```shell
user@WSL: /$ sudo apt autoremove -y && sudo apt autoclean -y
```
... and if kernel updates were installed, you'll want to reboot:
```shell
user@WSL: /$ sudo reboot
```
[`^ Top`](#update)
WSL2 configuration happens in 2 files:
* .wslconfig - is stored in your %USERPROFILE% directory in Windows and applies to **_ALL WSL INSTANCES_**
* /etc/wsl.conf - applies only to the **_instance it is part of_**
First, let's take care of your instance configuration file - /etc/wsl.conf:
(copy and paste everything below onto your linux command line)
```shell
user@WSL: /$ sudo tee /etc/wsl.conf > /dev/null <\.wslconfig`
#### OPTIONAL - Configure drvfs Mounts
I find it useful to be able to mount certain Windows directories under certain Linux directories depending upon the role intended for a WSL2 instance. For example, if an instance is to be a docker host, you may want to mount a specific location for docker volumes and other data under certain directories:
```shell
user@WSL: /$ sudo tee /etc/fstab > /dev/null < NOTE: If you do mount a folder as demonstrated above, make sure that you create the destination folder before you reboot, or FsTab will throw an error when it tries to mount the directory and can't find it.
[`^ Top`](#config)
> NOTE: You will only be able to install GUI support for Ubuntu on WSL2 if you can find your graphics card listed [HERE](https://developer.nvidia.com/cuda-gpus).
> I usually skip this step because it inflates the size of the `.vhdx` file for an instance quite considerably (bloat).
1. Install `gcc` if you haven't already:
```shell
user@WSL: /$ sudo apt install gcc -y
```
2. Install the CUDA keyring:
```shell
user@WSL: /$ sudo wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.0-1_all.deb
user@WSL: /$ sudo dpkg -i cuda-keyring_1.0-1_all.deb
```
3. Update & Install CUDA
```shell
user@WSL: /$ sudo apt update
user@WSL: /$ sudo apt install cuda -y
```
4. Install basic X11 applications
```shell
user@WSL: /$ sudo apt install x11-apps -y
```
[`^ Top`](#gui)
> **If you have any SSH keys that will be required by your WSL2 instances, now would be a good time to include them (eg: SSH key for GitHub)**
For the purposes of this guide, I'll assume that you've already got an SSH Key that you use to authenticate with GitHub set up and working. All that needs to happen is that you set up a `.ssh` folder under your WSL directory that you can copy your existing key into . So, using Powershell:
```powershell
PS E:\WSL> mkdir .ssh
PS E:\WSL> cp ~\.ssh\key_name .ssh\key_name
PS E:\WSL> cp ~\.ssh\key_name.pub .ssh\key_name.pub
PS E:\WSL> $text = "Host github.com"
PS E:\WSL> $text > .ssh\config
PS E:\WSL> $text = " IdentityFile ~/.ssh/key_name"
PS E:\WSL> $text >> .ssh\config
```
Then the easiest way to copy your `.ssh` folder to wherever it needs to be is like so:
```powershell
PS E:\WSL> cp -R .ssh \\wsl$\Ubuntu\home\ragdata
```
Then switch to your WSL terminal window and take care of permissions:
```shell
user@WSL: ~$ sudo chown -R ragdata:ragdata .ssh
user@WSL: ~$ chmod 0600 .ssh\*
user@WSL: ~$ chmod 0644 .ssh\*.pub config
```
And add a couple of lines to `.bashrc` to make the key available to the ssh-agent:
```shell
user@WSL: ~$ echo "eval $(ssh-agent) &> /dev/null" >> .bashrc
user@WSL: ~$ echo "ssh-add ~/.ssh/key_name &> /dev/null" >> .bashrc
user@WSL: ~$ . ~/.bashrc
```
[`^ Top`](#ssh)
> **The easiest way to install docker on WSL is to simply install Docker Desktop for Windows 11 and tick the boxes under settings for which WSL2 instance you want to have access to it. However, for the purposes of this guide, I'm going to assume that you intend to run docker on your Linux instances independently of Docker Desktop (because you might want to host a swarm)**
1. Install prerequisites:
```shell
user@WSL: ~$ sudo apt install ca-certificates curl gnupg2 lsb-release -y
```
2. Add Docker's official GPG key:
```shell
user@WSL: ~$ sudo mkdir -p /etc/apt/keyrings
user@WSL: ~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
```
3. Use the following command to set up the Docker repository:
```shell
user@WSL: ~$ echo \
> "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /de>v/null
```
4. Install Docker Engine
```shell
user@WSL: ~$ sudo apt update
user@WSL: ~$ sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
```
5. Create Additional Non-Root User
Because docker needs to grant some hefty privileges to a non-root user, it's a good idea to set up a user specifically for this:
```shell
user@WSL: ~$ sudo adduser dockeruser
```
Then grant that user sudo privileges:
```shell
user@WSL: ~$ sudo usermod -aG sudo dockeruser
```
Finally, add this user to the `docker` group:
```shell
user@WSL: ~$ sudo usermod -aG docker dockeruser
```
6. Create a config file for the `dockerd` daemon:
```shell
user@WSL: ~$ sudo mkdir -p /etc/docker
user@WSL: ~$ sudo tee /etc/docker/daemon.json > /dev/null <
[`^ Top`](#export)
1. Stop all instances of WSL
```Powershell
PS C:\> wsl --shutdown
```
2. Open Registry Editor (regedit) and go to: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss
* Each subfolder on Lxss represents a WSL instance
3. Locate and rename your distro by editing the `DistributionName` key in the appropriate subfolder - click OK
4. Open Powershell as Admin and restart WSL with the command:
```Powershell
PS C:\> Get-Service LxssManager | Restart-Service
```
[`^ Top`](#export)