The Coding Notebook
Memorable coding moments of a software engineer
Installing multiple WSL distros
Summary on installing multiple WSL distributions side-by-side.



# Intro
Installing the "Default" WSL distro can be done from the Microsoft store, but it is also possible to install additional WSLs, this is nice if you want a temporary sandbox or something like that.

This post is a summary from the great [StackExcahnge](https://superuser.com/questions/1515246/how-to-add-second-wsl2-ubuntu-distro-fresh-install) thread. The answers are from users [biswapriyo](https://superuser.com/users/726810/biswapriyo) and [pleasemorebacon](https://superuser.com/users/714595/pleasemorebacon).

**IMPORTANT**: This method works only if you have the `wsl.exe` command (Windows 10 Build 18305 or above). If not try using [LxRunOffline](https://github.com/DDoSolitary/LxRunOffline).

# Get Ubuntu distro
First we need to download a rootfs tarball from Ubuntu, these are available [here](https://cloud-images.ubuntu.com/releases/).
Download the `ubuntu-x.x-server-cloudimg-amd64-wsl.rootfs.tar.gz` file (x.x used as version number). Make sure the file name has `amd64-wsl` and the file type is `.tar.gz`.

Then we can install it using the `wsl` command:
```bash
wsl.exe --import <Distribution Name> <Install Folder> <.TAR.GZ File Path>
```

# Add non-root user
By default, when running the newly installed distro, it will run with the `root` user, we don't want that. Lets add a "normal" user.

First run the disto:
```bash
wsl -d <Distribution Name>
```

Next add a new user and then add it to the sudo group
```bash
adduser <username>
adduser <username> sudo
```

Next we'll set this new user to be the default user when the distro starts, this should be done by editing the `/etc/wsl.conf` file (which doesn't exist yet).
```bash
vi /etc/wsl.conf
```

And add this section:
```bash
[user]
default=<username>
```

That's it, type `logout` to exit and `wsl --shutdown <Distribution Name>` to terminate it. And then when running the distro again via `wsl -d <Distribution Name>` it should use the newly added user...