Moving WSL Distributions to Another Drive
Source: Dev.to
Moving WSL 2 Distributions to Another Drive
WSL 2 distributions default to your C: drive. That’s fine when you have a single small Ubuntu install, but it quickly becomes a problem when you have several distros each with a 20‑50 GB virtual disk and your system drive is running low on space.
Good news: you can move distributions to any drive.
Less‑good news: there are a few ways to do it, and the right method depends on your WSL version.
Where Are My Distributions Stored?
Before moving anything, locate where your distros currently live. WSL stores each distribution’s virtual hard disk (VHDX) in a base path registered in the Windows Registry:
HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\{GUID}\BasePath
Common default locations
| WSL version | Default path |
|---|---|
| Newer WSL | %LOCALAPPDATA%\wsl\{GUID}\ |
| Store‑installed distros | %LOCALAPPDATA%\Packages\\LocalState\ |
You can check the size of each VHDX from PowerShell:
Get-ChildItem -Path "$env:LOCALAPPDATA\wsl" -Recurse -Filter "ext4.vhdx" |
Select-Object FullName,
@{N='SizeGB';E={[math]::Round($_.Length/1GB, 2)}}
Or list all your distributions with their WSL versions:
wsl --list --verbose
Method 1 – wsl --manage --move (Recommended)
The simplest way to move a distribution is the built‑in move command. It relocates the VHDX file and updates the registry in one step.
Step 1 – Stop the distribution
wsl --terminate Ubuntu
Verify it’s stopped:
wsl --list --verbose
You should see Stopped next to the distro name.
Step 2 – Move it
wsl --manage Ubuntu --move "D:\WSL\Ubuntu"
WSL will create the destination folder if needed and move the VHDX file. Large VHDX files (e.g., 50 GB) may take several minutes depending on disk speed.
Step 3 – Verify
wsl -d Ubuntu
whoami
ls ~
If the commands run correctly, your distribution is now on D: and WSL knows where to find it. All files, packages, and configuration are preserved.
Method 2 – Export & Import
Use this when --manage --move isn’t available, or when you want to rename the distro. It works on all WSL 2 installations.
Step 1 – Export the distribution
You have three format options:
-
TAR (default, universal)
wsl --export Ubuntu D:\Backups\ubuntu-backup.tar -
VHD (faster, preserves disk structure)
wsl --export Ubuntu D:\Backups\ubuntu-backup.vhdx --format vhd -
Compressed TAR (smaller file)
wsl --export Ubuntu D:\Backups\ubuntu-backup.tar.gz --format tar.gz
The VHD format copies the VHDX directly and is considerably faster for large distros.
Step 2 – Unregister the old distribution
wsl --unregister Ubuntu
Warning: This removes the distro from WSL’s registry and deletes the original VHDX. Make sure the export completed successfully (check the file size) before running this command.
Step 3 – Import to the new location
From a TAR export
wsl --import Ubuntu "D:\WSL\Ubuntu" D:\Backups\ubuntu-backup.tar
From a VHD export
wsl --import Ubuntu "D:\WSL\Ubuntu" D:\Backups\ubuntu-backup.vhdx --vhd
The syntax is: wsl --import .
Step 4 – Fix the default user (only needed for TAR imports)
When importing from a TAR archive, WSL defaults to root. Set your default user by editing /etc/wsl.conf:
wsl -d Ubuntu -u root
cat >> /etc/wsl.conf **Caution:** This method bypasses the safety checks performed by `--export`/`--import`. Ensure the VHDX is not corrupted and that the destination folder contains only the VHDX (no extra files).
After importing, verify the distro works as described in **Method 1, Step 3**.
---
## Quick Reference Cheat‑Sheet
| Task | Command |
|------|---------|
| List distros & versions | `wsl --list --verbose` |
| Stop a distro | `wsl --terminate ` |
| Move (WSL ≥ 0.58) | `wsl --manage --move ""` |
| Export (TAR) | `wsl --export .tar` |
| Export (VHD) | `wsl --export .vhdx --format vhd` |
| Unregister | `wsl --unregister ` |
| Import (TAR) | `wsl --import "" .tar` |
| Import (VHD) | `wsl --import "" .vhdx --vhd` |
| Set default user | Edit `/etc/wsl.conf` with `[user] default=` |
| Delete backup file | `Remove-Item ` |
---
Now you can free up space on your system drive without reinstalling your WSL 2 distributions. Happy hacking!
## Move a VHDX File to a New Location
You can register the VHDX directly without copying it again:
```powershell
wsl --import-in-place Ubuntu "D:\WSL\Ubuntu\ext4.vhdx"
This tells WSL to use the VHDX at its current location.
The file must be ext4‑formatted (all WSL 2 VHDX files are).
It’s the fastest option if you have already moved the file yourself.
Choosing the Right Method
| Factor | --manage --move | Export/Import (TAR) | Export/Import (VHD) |
|---|---|---|---|
| Speed | Fast (direct move) | Slow (tar + extract) | Medium (file copy) |
| Disk space needed | Just the destination | 2× (export + import) | 2× (export + import) |
| Preserves user settings | Yes | No (need to fix) | Yes |
| Rename distro | No | Yes | Yes |
| WSL version required | Recent WSL | Any WSL 2 | Any WSL 2 |
| Complexity | Low | Medium | Medium |
Recommendation: For most people,
--manage --moveis the right choice. Use export/import when you need to rename the distro or are on an older WSL version.
Installing New Distros on a Different Drive
Prevent the need to move later by specifying the location during installation:
wsl --install Ubuntu --location "D:\WSL\Ubuntu"
The VHDX is created on D: from the start.
The Easy Way: WSL UI
WSL UI provides a point‑and‑click way to move distributions.
Move Distribution dialog
- Shows the current location and disk size
- Lets you browse to a new location
- Handles stopping the distro, moving the files, and updating the registry
- Shows progress for large moves
No command line, no manual registry edits. It uses WSL’s native move command under the hood, preserving files, settings, default user, and configuration.
Troubleshooting
| Symptom | Cause / Fix |
|---|---|
“The operation is not supported” when using --manage --move | You may be on an older WSL version. Run wsl --update or fall back to export/import. |
| Import defaults to root user | Expected with TAR imports. Edit /etc/wsl.conf (see “Fix default user” below). |
| “Access is denied” during move | Ensure no WSL processes are using the distro. Run wsl --shutdown then retry. |
| Distro not showing after import | Verify the import path exists and you have write permissions. Run PowerShell as Administrator. |
| Running out of space during export | Export directly to the destination drive (e.g., D:\Backups\ when moving from C: to D:). |
Summary
| Task | Command |
|---|---|
| List distros | wsl --list --verbose |
| Stop a distro | wsl --terminate |
| Move (simple) | wsl --manage --move "D:\WSL\path" |
| Export (TAR) | wsl --export backup.tar |
| Export (VHD) | wsl --export backup.vhdx --format vhd |
| Unregister | wsl --unregister |
| Import (TAR) | wsl --import "D:\path" backup.tar |
| Import (VHD) | wsl --import "D:\path" backup.vhdx --vhd |
| Import in‑place | wsl --import-in-place "D:\path\ext4.vhdx" |
| Install on D: | wsl --install Ubuntu --location "D:\WSL\Ubuntu" |
| Fix default user | Edit /etc/wsl.conf → [user] → default=username |
Moving a distro is a one‑time (or occasional) task, but it can free up a lot of space on a crowded C: drive.
*Originally published at *