Change WSL/Docker files to another disk

Gabriel Tavares - Sep 1 - - Dev Community

Introduction

I'm writing this post to help when I forget how to do this or if someone else needs a little help with this kinda of issue.

Motivation

I use more than one SSD. My main SSD was being filled with my development files from WSL and Docker. So I wanted find a way to move this data to another disk. Testing and searching I found a way to do so.

Getting Things Done

First of all you need to check if your WSL is running:

wsl -l -v
Enter fullscreen mode Exit fullscreen mode

You might get something like this:

  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2
Enter fullscreen mode Exit fullscreen mode

if STATE is Running you have to shutdown WSL:

wsl  --shutdown
Enter fullscreen mode Exit fullscreen mode

Now we will export the WSL data to another place:

wsl --export docker-desktop-data "<your-new-wsl-data-location>\docker-desktop-data.tar"
Enter fullscreen mode Exit fullscreen mode

Exporting data maybe will take a while. When finished, we need to unregister the distro by using this command:

wsl --unregister docker-desktop-data
Enter fullscreen mode Exit fullscreen mode

WARNING: your ext4.vhdx data will be removed as well from the original file destination.

wsl --import docker-desktop-data "<new-data-location-folder>" "<new-data-location-folder>\docker-desktop-data.tar" --version 2
Enter fullscreen mode Exit fullscreen mode

WARNING: you see we put a flag --version 2, this is the version of WSL distro.

Conclusion

You can delete ONLY the <your_docker_path>\wsl\data\docker-desktop-data.tar file. Don't delete others files the might be in the folder!

Thanks for read until right here and I hope this help.

. .