Moving WSL to Another Drive
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.
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 | wsl --list --verbose |
If the output is like , it means your WSL is down. If not, run wsl --shutdown
to … shut it down. 😌
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.
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.
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.
Then, you can start import. Remember the directory we created before? Will place our file system there.
1 | # wsl --import distro destination source |
And you will se this.
Step 4. Finishing up
Now, finally, we got to set up our WSL again. There won’t be any output on success.
1 | cd $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps |
Notice: If you’re using Ubuntu 20.04, the executable file should be
ubuntu2004.exe
. Otherwise, please usels
command to check it by yourself.
Ta-da!🎉 Now you can run WSL again!
Easy, huh? :)