Change WSL/Docker files to another disk
Gabriel Tavares

Gabriel Tavares @gabrielmodog

About: ENG: I just want to share what I wanted to hear from the people before. PT_BR: Eu só quero compartilhar o que eu queria ouvir das pessoas antes.

Location:
Brazil
Joined:
Nov 29, 2019

Change WSL/Docker files to another disk

Publish Date: Sep 1 '24
2 0

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.

Comments 0 total

    Add comment