Kevin's Blog

Some Tips About WSL2


I installed WSL1 back in April 2019. What a time. It kinda sucked back then.

Then WSL2 came out in 2020. I held off for a few years because of an awkward situation: WSL2 required virtualization turned on, but hit first-person spyware VALORANT from Riot Games® required me to turn it off to play. 1:

Around May 2022 I finally decided to cutover to WSL2, and I foolishly went with 20.04 despite 22.04 having just come out.

Well, it’s almost May 2026 now and 20.04 is going out of LTS, so I have to finally do some maintenance.

There’s a lot of legacy and different ways to do things with WSL, so I wrote some tips here.

Everything here is specifically WSL2 because a lot changed between WSL1 and WSL2. That, it iself, is a pain for search optimization, and probably LLMs too.

You should update your wsl.exe command itself

For a while I didn’t even know what version of wsl.exe I had because wsl --version didn’t work. Apparently the --version flag itself came in a later version - in November 2022. Damn, that’s what I get for being an early adopter.

Much like npm or other commands, wsl has a built-in way to update itself:

wsl --update

Moving WSL2 Distros

You may want to move distros if they were installed on a drive that’s running out of space, to a disk with more space.

In this example below, let’s assume you have another disk at D:\, and you are moving your Ubuntu-20.04 distro (like I did).

The Easy Way: —manage —move

Latest versions of wsl have an easy solution using these flags.

# View distro names
wsl -l -v


# Terminat instances
wsl --shutdown

# Confirm no more are running
wsl -l -v

# Long-term folder to store your distro files. You can name it whatever.
mkdir D:\WSL\Ubuntu-20.04
# Import to a new permanent location on the D:\ drive
wsl --manage Ubuntu-20.04 --move D:\WSL\Ubuntu-20.04

The Hard Way: export and import (which I ended up doing accidentally)

Click here for details about the hard way

From cmd.exe or powershell:

# View distro names
wsl -l -v

# Terminat instances
wsl --shutdown

# Confirm no more are running
wsl -l -v

# Create a place to store backup
mkdir D:\Path\To\Backup\Folder

# Takes a few minutes. To check progress, look at the file's size in File Explorer
# Replace Ubuntu-20.04 with the name of your distro, from the `wsl -l -v` command
wsl --export Ubuntu-20.04 D:\Path\To\Backup\Folder\ubuntu-backup-filename.tar

wsl --unregister Ubuntu-20.04
# This should also delete the ext4.vhdx from your LocalState folder, freeing disk space on your main drive (persumably C:\)

# Long-term folder to store your distro files. You can name it whatever.
mkdir D:\WSL\Ubuntu-20.04
# Import to a new permanent location on the D:\ drive
wsl --import Ubuntu-20.04 D:\WSL\Ubuntu-20.04 D:\Path\To\Backup\Folder/ubuntu-backup-filename.tar --version 2

Now, open your Ubuntu terminal with something like Windows Terminal. You may notice it logs you back into root. See the next section about how to set default user.

Setting Default User

Easy but legacy: config —default-user

A common solution to this is to run a command like ubuntu config --default-user youruser. This is the suggestion that Microsoft themselves suggest, although it’s very poorly documented in my opinion.

You probably aren’t familiar with the fact that your WSL2 distro is itself a Windows executable. For me, my executable was actually called ubuntu2004.exe. No, not the year 20042, that’s just 20.04 shortened in a really confusing way.

Anyway, run something like

ubuntu2004 config --default-user yourname

Apparently though, future version of Ubuntu don’t always ship with an executable, so this might not be the best way going forward. In that case…

Slightly harder but more modern: edit /etc/wsl.conf

Inside your Linux distro, you can edit the /etc/wsl.conf file and concat the following contents:

[user]
default=yourname

Installing a new distro on non-C drive

Alright, so all that work to move an existing distro was a pain in the ass. I’m sure installing a fresh distro won’t be too bad?

Welp.

Go to this ugly Apache website, and go to the only release avaialble. Pray it’s the one you actually want. Don’t know what the Ubuntu version codename maps to? Go Google it. Man, what a hostile user experience. Anyway, download the .wsl image and put it somewhere convenient.

Now run this:

# noble-wsl-amd64.wsl is the file I downloaded. Noble is Ubuntu 24.04.
wsl --import Ubuntu-24.04 D:\WSL\Ubuntu-24.04\ 'D:\Path\To\Your\Convenient\Downloaded\noble-wsl-amd64.wsl' --version 2

Once you do that, you will get logged in as root. Go create a sudo user:

createuser yourusername
usermod -aG sudo yourusername

# See previous section about this file
sudo vim /etc/wsl.conf

Copying files from previous distro to new distro

TBD! Haven’t done that yet. I’m going to bed, this already took way too long.

Footnotes

  1. Well the common solution is to have a motherboard with TPM 2.0, which my motherboard didn’t (still doesn’t!) have. Shoutout Windows 11 for trying to get me to upgrade just for TPM 2.0. (I won’t!) https://web.archive.org/web/20260218200305/https://support-valorant.riotgames.com/hc/en-us/articles/16941220890899-Addressing-Virtualization-based-security-VBS-settings-on-Windows-10-VAN9005-VALORANT

  2. coincidentally Ubuntu’s first release was 4.10 released in October 2004. I don’t have to archive.org Wikipedia right? Well whatever I’m lazy