Have you ever found yourself staring at a nearly full C: drive while your spacious secondary drive sits idle, waiting for your precious data to be stored? If you are running WSL2 with Ubuntu and Docker Desktop for development, this is a very common pain point. Let me walk you through how I freed up 40 GB+ on my system drive by relocating these utilities to my secondary drive.
You may ask, Why Does Any of This Matter?
The answer lies in the fact that WSL2 stores virtual hard disk files with a .vhdx extension. This virtual disk grows significantly as Docker containers and Machine Learning workloads accumulate. Docker Desktop compounds this by creating its own hidden WSL distributions. Relocating these distributions to a larger drive not only frees up system space, but also improves overall system performance, as the Operating System has more room to breathe.
Let's look at how to relocate these files.
Step 1: Relocate Your Ubuntu WSL Distribution
First, let's move your primary Ubuntu Installation:
Open Powershell and type:
# Shutdown all WSL instances
wsl --shutdown
# Export your Ubuntu distribution to a backup file on your secondary drive
wsl --export Ubuntu <Secondary_Drive_Name>:\WSL\ubuntu.tar
# Unregister the current distribution. This frees up space on your C: drive
wsl --unregister Ubuntu
# Import it to the new location on secondary drive
wsl --import Ubuntu <Secondary_Drive_Name>:\WSL\Ubuntu <Secondary_Drive_Name>:\WSL\ubuntu.tar --version 2
# Set your default user (find your username with: wsl -d Ubuntu cat /etc/passwd)
ubuntu config --default-user <yourusername>
You may see these text prompts after typing the commands:
Step 2: Move Docker Desktop Data
Docker Desktop is a tricky case as it manages its internal WSL distributions. Instead of exploring those distributions and struggling with their relocation, a cleaner approach is recommended:
1. Stop Docker Desktop completely (right-click system tray icon -> Quit)
2. Shutdown WSL by typing this command in Powershell:
wsl --shutdown
3. Move the Docker data folder:
# Create new directory on E: drive
mkdir <Secondary_Drive_Name>:\WSL\Docker
# Move Docker's WSL data
Move-Item "C:\Users\<YourUsername>\AppData\Local\Docker\wsl" "<Secondary_Drive_Name>:\WSL\Docker\wsl"
4. Update Docker Desktop Settings
- Open Docker Desktop
- Go to Settings -> Resources -> Advanced
- Change Disk Image Location to
<Secondary_Drive_Name>:\WSL\Docker\wsl - Click Apply & Restart
Step 3: Clean Up Leftover Files
After moving everything, clean up the leftover files to recover the used space. This can be done by removing the temporary ubuntu.tar file created during the export process. This file should be located in:
<Secondary_Drive_Name>:\WSL\ubuntu.tar
Bonus Step: Verify GPU access in Ubuntu terminal
If your system has an Nvidia GPU, you can verify its access in the Ubuntu terminal.
nvidia-smi
If this appears as a result of this command, Congratulations!
You have successfully relocated WSL Ubuntu in your secondary drive without altering any configuration whatsoever. This is because GPU acceleration works perfectly after relocation because Nvidia drivers remain on your Windows system while only the data moves.
Final Thoughts
Moving WSL2 and Docker to another drive is a game-changer for developers with limited system drive space. The process takes about 15 minutes but can free up dozens of gigabytes. Best of all, your development environment remains completely intact—no need to reinstall packages or rebuild containers.
Remember: Always backup important data before moving system files, and test your critical workflows after migration.
Till then, Happy Coding!!



Top comments (0)