close
close

Change WSL/Docker files to another drive

Change WSL/Docker files to another drive

Introduction

I’m writing this post to help if I forgot how to do this or if anyone else needs a little help with this kind of problem.

Motivation

I use more than one SSD. My main SSD was filled with my WSL and Docker development files. So I wanted to find a way to move this data to another drive. Through testing and searching I found a way to do this.

Getting things done

First, check if your WSL is active:

wsl -l -v
Go to full screen mode

Exit full screen

You could then get something like this:

  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2
Go to full screen mode

Exit full screen

as STATE is Running You must close WSL:

wsl  --shutdown
Go to full screen mode

Exit full screen

Now we export the WSL data to another place:

wsl --export docker-desktop-data "\docker-desktop-data.tar"
Go to full screen mode

Exit full screen

Exporting data may take a while. When we are done, we need to unregister the distro with this command:

wsl --unregister docker-desktop-data
Go to full screen mode

Exit full screen

WARNING: your ext4.vhdx Data is also deleted from the original file destination.

wsl --import docker-desktop-data "" "\docker-desktop-data.tar" --version 2
Go to full screen mode

Exit full screen

WARNING: see we put up a flag --version 2this is the WSL distribution version.

Conclusion

You can delete ONLY the \wsl\data\docker-desktop-data.tar file. Do not delete any other files that may be in the folder!

Thanks for reading this far. I hope it helps.