How to move WSL Distribution to Another Drive

Adi Purnomo
2 min readJan 9, 2024

--

Ubuntu and Windows

Hello there,

If you have ever felt that your disk space on your C drives running out due to the big WSL distribution. You can manage your WSL distribution by moving it to another drive. Here’s a simple guide for you:

Prerequisites:
make sure you are using a Windows operating system with WSL 2 installed

1. First thing first, let’s see what WSL 2 installation you have. Open a WSL or Power Shell in your Windows terminal and type:

wsl --list -v

PS C:\Users\medival> wsl --list -v
NAME STATE VERSION
* rancher-desktop Stopped 2
docker-desktop-data Stopped 2
docker-desktop Stopped 2
Ubuntu-22.04 Running 2
Ubuntu-20.04 Stopped 2
rancher-desktop-data Stopped 2

2. If the Linux distribution you want to move is currently running, you need to stop it. For example, if it’s Ubuntu 22.04, just use:

wsl -t Ubuntu-22.04

3. Now, let’s export your Ubuntu 22.04 distribution to the folder. We’ll save it as “ubuntu-22.04” in D:\workspaces\wsl\ubuntu-22.04.tar. Type the following command:

wsl --export Ubuntu-22.04 "D:\workspaces\wsl\ubuntu-22.04.tar"

Note: This may take some time depending on how much your distribution size. For mine, it takes around 6 minutes

4. Once done, go to drive D:\workspace\wsl and make sure ubuntu-22.04.tar is exists

5. Next, we can safely remove Ubuntu-22.04 distribution by running the following command:

wsl --unregister Ubuntu-22.04

Optionally you can verify the Ubuntu-22.04 by running

wsl --list -v

6. Once we remove it, it’s time to import the new WSL installation to a new folder and re-register it. We’ll import Ubuntu 22.04 to “D:\workspaces\wsl\ubuntu-22.04 using our exported files

wsl --import Ubuntu-22.04 "D:\workspacves\wsl\ubuntu-22.04" "D:\workspaces\wsl\ubuntu-22.04.tar"

7. If you are importing to a new machine or creating a new user for Ubuntu. You can set the default username to avoid login prompts every time you launch the distribution.

ubuntu.exe config --default-user yourusername

And that’s it! You’ve successfully moved your Ubuntu 22.04 WSL distribution to another drive. Now you can fire it up and keep on using it in its new location. If you check your C drive there will be more space

--

--

Adi Purnomo
Adi Purnomo

No responses yet