DEV Community

Cover image for Moving WSL Distributions to Another Drive
Ian Packard for Octasoft Ltd

Posted on • Originally published at wsl-ui.octasoft.co.uk

Moving WSL Distributions to Another Drive

WSL2 distributions default to your C: drive. That's fine when you have one small Ubuntu install. It's less fine when you have five distros, each with a 20-50GB virtual disk, and your system drive is running out of space.

The good news: you can move distributions to any drive. The less good news: there are a couple of ways to do it, and the right approach depends on your WSL version.

Where Are My Distributions Stored?

Before moving anything, let's find 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
Enter fullscreen mode Exit fullscreen mode

Common default locations:

  • Newer WSL: %LOCALAPPDATA%\wsl\{GUID}\
  • Store-installed distros: %LOCALAPPDATA%\Packages\<distro-package>\LocalState\

You can check your distro sizes from PowerShell:

Get-ChildItem -Path "$env:LOCALAPPDATA\wsl" -Recurse -Filter "ext4.vhdx" |
  Select-Object FullName, @{N='SizeGB';E={[math]::Round($_.Length/1GB, 2)}}
Enter fullscreen mode Exit fullscreen mode

Or list all your distributions and their WSL versions:

wsl --list --verbose
Enter fullscreen mode Exit fullscreen mode

Method 1: wsl --manage --move (Recommended)

The simplest way to move a distribution is WSL's built-in move command. This relocates the VHDX file and updates the registry in one step.

Step 1: Stop the Distribution

The distro must be stopped before moving:

wsl --terminate Ubuntu
Enter fullscreen mode Exit fullscreen mode

Verify it's stopped:

wsl --list --verbose
Enter fullscreen mode Exit fullscreen mode

Look for "Stopped" next to your distro name.

Step 2: Move It

wsl --manage Ubuntu --move "D:\WSL\Ubuntu"
Enter fullscreen mode Exit fullscreen mode

WSL will create the destination directory if needed and move the VHDX file. This can take a while for large distros — a 50GB VHDX will take a few minutes depending on your disk speed.

Step 3: Verify

Start the distro and confirm everything works:

wsl -d Ubuntu
Enter fullscreen mode Exit fullscreen mode
whoami
ls ~
Enter fullscreen mode Exit fullscreen mode

That's it. Your distribution is now on D: and WSL knows where to find it. All your files, installed packages, and configuration are preserved.

Method 2: Export and Import

If --manage --move isn't available on your WSL version, or if you want to rename the distro at the same time, the export/import approach works on all WSL2 installations.

moving-wsl-distributions-to-another-drive/export-import-workflow

Step 1: Export the Distribution

You have two format options:

TAR format (default, universal):

wsl --export Ubuntu D:\Backups\ubuntu-backup.tar
Enter fullscreen mode Exit fullscreen mode

VHD format (faster, preserves disk structure):

wsl --export Ubuntu D:\Backups\ubuntu-backup.vhdx --format vhd
Enter fullscreen mode Exit fullscreen mode

The VHD format is significantly faster because it copies the VHDX file directly instead of creating a tar archive from the filesystem. For large distros, this can save considerable time.

Compressed TAR (smaller file):

wsl --export Ubuntu D:\Backups\ubuntu-backup.tar.gz --format tar.gz
Enter fullscreen mode Exit fullscreen mode

Step 2: Unregister the Old Distribution

This removes the distribution from WSL's registry and deletes the original VHDX:

wsl --unregister Ubuntu
Enter fullscreen mode Exit fullscreen mode

Warning: This deletes the original distribution data. Make sure your export completed successfully before running this. Check the file size of your export — it should be reasonable (not 0 bytes).

Step 3: Import to the New Location

From a TAR export:

wsl --import Ubuntu "D:\WSL\Ubuntu" D:\Backups\ubuntu-backup.tar
Enter fullscreen mode Exit fullscreen mode

From a VHD export:

wsl --import Ubuntu "D:\WSL\Ubuntu" D:\Backups\ubuntu-backup.vhdx --vhd
Enter fullscreen mode Exit fullscreen mode

The arguments are: wsl --import <name> <install-location> <file-path>.

Step 4: Fix the Default User

When you import from a TAR archive, WSL defaults to logging in as root. You need to restore your default user. Edit /etc/wsl.conf inside the distro:

wsl -d Ubuntu -u root
Enter fullscreen mode Exit fullscreen mode
cat >> /etc/wsl.conf << 'EOF'
[user]
default=yourusername
EOF
exit
Enter fullscreen mode Exit fullscreen mode

Then restart the distro for the change to take effect:

wsl --terminate Ubuntu
wsl -d Ubuntu
whoami
Enter fullscreen mode Exit fullscreen mode

This should now show your username instead of root.

Note: If you exported as VHD format, the /etc/wsl.conf file is preserved as-is inside the VHDX, so your default user setting should already be correct.

Step 5: Clean Up

Once everything is working, delete the backup file:

Remove-Item D:\Backups\ubuntu-backup.tar
Enter fullscreen mode Exit fullscreen mode

Method 3: Import In-Place (Advanced)

If you've already manually copied a VHDX file to a new location, you can register it directly without WSL copying it again:

wsl --import-in-place Ubuntu "D:\WSL\Ubuntu\ext4.vhdx"
Enter fullscreen mode Exit fullscreen mode

This tells WSL to use the VHDX at its current location. The file must be ext4-formatted (which all WSL2 VHDX files are). This is the fastest option if you've 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 2x (export + import) 2x (export + import)
Preserves user settings Yes No (need to fix) Yes
Rename distro No Yes Yes
WSL version required Recent WSL Any WSL2 Any WSL2
Complexity Low Medium Medium

For most people, --manage --move is 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

Prevention is better than cure. When installing new distributions, you can specify the location upfront:

wsl --install Ubuntu --location "D:\WSL\Ubuntu"
Enter fullscreen mode Exit fullscreen mode

This puts the VHDX on D: from the start, avoiding the need to move it later.

The Easy Way: WSL UI

WSL UI makes moving distributions a point-and-click operation. The Move Distribution dialog:

  1. Shows the current location and disk size
  2. Lets you browse to a new location
  3. Handles stopping the distro, moving the files, and updating the registry
  4. Shows progress for large moves

No command line, no worrying about which method to use, no manual registry updates. It uses WSL's native move command under the hood, so everything is preserved — your files, settings, default user, and configuration.

Troubleshooting

"The operation is not supported" when using --manage --move:
You may be on an older WSL version. Update with wsl --update or use the export/import method instead.

Import defaults to root user:
This is expected with TAR imports. Edit /etc/wsl.conf as described in Step 4 of Method 2.

"Access is denied" during move:
Make sure no WSL processes are using the distro. Run wsl --shutdown to stop everything, then try again.

Distro not showing after import:
Check that the import path exists and you have write permissions. Try running PowerShell as Administrator.

Running out of space during export:
Export to the destination drive directly. For example, if moving from C: to D:, export to D:\Backups\ instead of a location on C:.

Summary

Task Command
List distros wsl --list --verbose
Stop a distro wsl --terminate <distro>
Move (simple) wsl --manage <distro> --move "D:\WSL\path"
Export (TAR) wsl --export <distro> backup.tar
Export (VHD) wsl --export <distro> backup.vhdx --format vhd
Unregister wsl --unregister <distro>
Import (TAR) wsl --import <name> "D:\path" backup.tar
Import (VHD) wsl --import <name> "D:\path" backup.vhdx --vhd
Import in-place wsl --import-in-place <name> "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 one of those tasks you only do once or twice, but it makes a real difference when your C: drive is filling up.


Originally published at https://wsl-ui.octasoft.co.uk/blog/moving-wsl-distributions-to-another-drive

Top comments (0)