Setting up custom Ubuntu version with Windows Subsystem for Linux (WSL)

Madhawa Perera
6 min readJul 25, 2023

Today, I got a new Windows machine, and I wanted to set up WSL (Windows Subsystem for Linux). I realized it would be helpful to create a post serving as both a personal note for myself and a simple guide for others who might be interested.

So to begin the setup process, the first thing I did was open PowerShell (PS) as an administrator (See Figure 1 below). Well, of course, I made a few minor changes to the terminal’s appearance :).

Figure 1: Windows PowerShell

I wanted to install WSL without any default Linux distributions that come with WSL. To do this, you should use the command wsl --install --no-distribution. (You can use wsl --install if you are happy with the default Linux distribution that comes with Microsoft Store Version). Once you do that, you will get a similar message as shown in Figure 2 below. Restart your computer to make the installation effective. You can type the Restart-Computer command in PowerShell for this.

Figure 2: Installation of WSL

Once you restart you can use the commands wsl --list or wsl --list verbose to check the Linux distribution that has been installed. However, since we decided not to use the default distribution, you should see the message “Windows Subsystem for Linux has no installed distributions.” To view the available Linux distributions that can be installed, simply use wsl --list --online. This will display a list of all the available distributions that you can install (refer to Figure 3 below).

Figure 3: WSL Distribution List

Next, we can install the latest Ubuntu distribution. To do that, first, download the distribution you want to install. In my case, I wanted to install Ubuntu 22.04.2 (Jammy Jellyfish). As shown in below, you can use the Invoke-WebRequest command in PowerShell to download (Make sure to give a proper download file path). Alternatively, you can copy and paste the URI on the browser or use the curl command to download Ubuntu using the command curl.exe -O https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-root.tar.xz. The “-O” in the curl command here will save the file in the current working directory with the same file name as the remote file. On the other hand, “-o” allows you to specify a different file name or location. Choose the argument that suits your needs. Please note that curl will not work on Windows PS by default (though it works on Windows Command line). You have to use curl.exe with PS. In my case I used Invoke-WebRequest as below.

Invoke-WebRequest -URI https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-root.tar.xz -OutFile /filepath/jammy-server-cloudimg-amd64-root.tar.xz

Now that we have the distribution we want, we can start installing this on WSL. However, before doing that, I wanted to check which WSL version I am running. To do that, simply execute the command wsl -v or wsl --version. I found that I was on WSL 1, but I want to install Ubuntu Jammy Jellyfish with WSL 2. To do so, firstly go to the Ubuntu distribution download location, and then execute the following command as shown in Figure 4 below. Don’t forget the--version 2 bit at the end of that command. Here, for <distribution_name>, you can provide any name you like, e.g., Ubuntu22.04, and for <path_to_downloaded_Ubuntu_Image>, use the path to the downloaded Ubuntu image. See the below command.

wsl --import <distribution_name> <path_to_downloaded_Ubuntu_Image> jammy-server-cloudimg-amd64-root.tar.xz --version 2
Figure 4: Installing WSL distribution

Once you see the message “The operation completed successfully” use the command wsl -l -v to see the installed distribution and corresponding WSL version. See Figure 5 below.

Figure 5

Next, run wsl -d <distribution_name> or wsl --distribution <distribution_name> (e.g. wsl -d Ubuntu22.04 in my case) to enter the Ubuntu subsystem. Once you are inside the Ubuntu subsystem, you can execute lsb_release -a to see which version of Ubuntu is running, as shown in Figure 6 below. Here, ‘lsb’ stands for Linux Standard Base. I am not sure why I am seeing the “No LSB modules are available” message; however, I found online that running sudo apt install lsb-core may fix this. Please let me know if you know why this message was printed and if sudo apt install lab-core will fix this.

Figure 6

One thing to notice is that you have logged in as the root user here. To test this, you can use the whoami command on the Linux terminal. However, if you want to create a new Linux user and grant them sudo privileges, you can use the following commands within the Ubuntu subsystem. However, this is an optional task.

To create a user in Linux, you can use the adduser <username> or useradd <username> command. Using adduser is recommended for most Linux distributions. Replace <username> with the desired username of the new user. The adduser command will prompt you to set a password and provide other user information interactively. Then, add the created user to the sudo group using the command sudo usermod -aG sudo <username>. After that, check if the user is now part of the sudo group by using groups <username> These steps will create a new user and grant them sudo privileges on the Linux system. See Figure 7 where I have demonstrated these steps.

Figure 7

One last thing you may want to do is to make this created user the default user for the WSL distribution you created. In other words, instead of logging in as the root user every time and then switching to this created user, you can set the created user as the default user for the distribution, so it automatically logs in with that user by default (and will prompt for the password). To do this within the Linux environment, you can use the following commands. Firstly use sudo to add the "[user]" line to the /etc/wsl.conf file by using sudo echo “[user]” >> /etc/wsl.conf. Again use sudo to add the "default=<username>" line to the /etc/wsl.conf file with the command sudo echo “default=<username>” >> /etc/wsl.conf. Replace <username> with the name of the created user. Then exit from the Linux system using the command exit, terminate the WSL distribution using the wsl -t <distribution_name> command. Finally log in again, and this time you will be logged in with the created user as the default. Refer to Figure 8 below for a demonstration of these steps.

Figure 8

That is it. So, we have managed to set up WSL on Windows with a custom Linux image. Optionally, we discussed how to create a new user for that distribution and make them the default user.

If this article helps you and want to thank me, you can buy me a virtual coffee by clicking the ‘Buy me a coffee’ button below. :)

Thanks for the read and I will see you in another article soon. Cheers!

--

--

Madhawa Perera

Research Engineer at CSIRO, HCI Researcher, and Sessional Academic at ANU. Passionate about crafting human-centered AI experiences through Mixed Reality (AR/VR)