Scenario

WSL is a great stuff! 😍 But sometimes, it may take up too much space in C drive, especially its ext4 file system. So in this article, I’d like to show how to move it to another drive so as to release drive storage pressure.

image-20230512194401252

Reference: https://woshub.com/move-wsl-another-drive-windows/


Procedures

Step 1. Preparation

First, you should make sure you know your username and password of WSL. If not, just open it, and use whoami command to find it out. Then, your WSL should be shutdown. In PowerShell, run the following command to make sure your WSL is down.

1
2
wsl --list --verbose
wsl --shutdown

If the output is like , it means your WSL is down. If not, run wsl --shutdown to … shut it down. 😌

image-20230512194650823

Notice: Here, remember the name of your distribution. :)

Then, create some directories. For example, here, I created Backup\ for intermediate file backup, and Storage\ for the final location.

image-20230512200221001

Step 2. Export WSL File System

Now, it’s time to export WSL to another place. So, open your PowerShell, and execute the following command. Remember to replace the directory with your own.

1
wsl --export Ubuntu-20.04 E:\IDE\WSL\Backup\ubuntu.tar

If everything goes well, you will see this.

image-20230512201119392

Step 3. Import WSL File System

Before your import stuffs, there are few steps to go. First, you got to unregister your WSL temporarily.

1
wsl --unregister Ubuntu-20.04

And you will see the following output.

image-20230512201229395

Then, you can start import. Remember the directory we created before? Will place our file system there.

1
2
# wsl --import distro destination source
wsl --import Ubuntu-20.04 E:\IDE\WSL\Storage E:\IDE\WSL\Backup\ubuntu.tar

And you will se this.

image-20230512201755671

Step 4. Finishing up

Now, finally, we got to set up our WSL again. There won’t be any output on success.

1
2
cd $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps
.\ubuntu2004.exe config --default-user your_username

Notice: If you’re using Ubuntu 20.04, the executable file should be ubuntu2004.exe. Otherwise, please use ls command to check it by yourself.

Ta-da!🎉 Now you can run WSL again!


Easy, huh? :)