Move WSL to another drive

Hafiz Azhar
2 min readFeb 17, 2024

--

WSL (Windows Subsystem for Linux) is a great feature by Windows to run Linux distro on Windows environment. It’s like having the best of both worlds in one environment, even though WSL is just another VM framework for me.

Recently, when working with WSL Ubuntu, to develop a huge machine learning data, I came to cross a problem, my disk suddenly blow up. It is turn out that WSL is using default C:\ drive and I am having a small SSD of 512GB only, well that’s the case.

So I’ve been trying to figure out on how do I actually move the WSL from C to my other bigger SSD.

I tried the classic way, using Windows to move the WSL installation disk, and guess what? Not working.

So I’ve been digging around. Turns out the steps are more simple than that.

Using the WSL command line tool

  1. Export the distribution. Create a .tar file with the distribution to move using wsl.exe --export. In my case it would be Ubuntu-22.04.
wsl.exe --export <DistroName> <Tar-FileName>

For example:

wsl.exe --export Ubuntu-22.04 D:\WSL\Ubuntu-22.04\Ubuntu-22.04.tar

2. Import the distribution into the target folder. Then, you can import the exported distribution into another folder

wsl.exe --import <DistroName> <Folder-To-Install> <Tar-FileName>

For example:

wsl.exe --import Ubuntu-22.04 D:\WSL\Ubuntu2204\ D:\WSL\Ubuntu22.04\Ubuntu22.04.tar

It would show something like this:

3. Delete old installation (optional). If you want to delete the old installation to free up more space.

wsl.exe --unregister <OldDistroName>

4. Run new distro. Spin up new distro in new disk.

wsl.exe -d <NewDistributionName>

For example:

wsl.exe -d Ubuntu-22.04

That’s all.

Now I can freely abuse my Ubuntu to use more space. Just kidding :)

Hopefully this article will help you a lot in managing the WSL distro on your system.

--

--

Hafiz Azhar

Full Stack Developer | Blockchain Architect | AI Developer | Programming Enthusiast