← All posts

Moving WSL2 Ubuntu to Another Drive Without Reinstalling Everything

A WSL2 Ubuntu installation can grow surprisingly quickly. Git repositories, Node dependencies, Docker layers, virtual environments, large datasets and local models all consume space inside the distribution's virtual hard disk. If that disk lives on the Windows system drive, moving it to a larger secondary drive can be more practical than reinstalling everything.

In July 2026, I moved my Ubuntu environment from the C: drive to E:\WSL\Ubuntu. The migration succeeded, although I encountered a permissions error and later a confusing Node/Codex PATH problem. Both are worth understanding before attempting the move.

Start with a verified backup

The safest general approach is to export a stopped WSL2 distribution as a VHDX, retain that backup, and import a separate copy under a temporary new distribution name. This preserves the original until the migrated installation has been verified. Do not unregister the original first: unregistering permanently deletes its registered filesystem.

The following PowerShell commands assume the original distribution is called Ubuntu. Replace the paths and names for your environment. Confirm that the backup and destination have sufficient free space, ideally with a separate backup drive.

wsl --list --verbose
wsl --version
# Save all Linux work before shutting down WSL.
wsl --shutdown
New-Item -ItemType Directory -Force E:\WSL\Ubuntu | Out-Null
New-Item -ItemType Directory -Force F:\WSLBackups | Out-Null
wsl --export Ubuntu F:\WSLBackups\Ubuntu-backup.vhdx --vhd

Check the command's exit code and that the exported VHDX exists. If the export fails, stop and diagnose before continuing. If the installed WSL version does not support VHDX export, update WSL according to your organization's policy or use the documented tar export/import alternative.

Copy the exported disk to its permanent home. Import the copy, not the only backup:

Copy-Item F:\WSLBackups\Ubuntu-backup.vhdx E:\WSL\Ubuntu\ext4.vhdx
wsl --import-in-place Ubuntu-Moved E:\WSL\Ubuntu\ext4.vhdx
wsl -d Ubuntu-Moved

The imported name does not have to match the old name. Keeping a distinct name also avoids destructive operations during testing. Avoid running services in both copies simultaneously if they share external state or bind the same ports.

Verify the installation before cleaning up

Inside the migrated distribution, check the user, filesystem and important project directories:

whoami
id
df -h /
ls -lah /home
command -v git
command -v node

An imported distribution may start as root. If necessary, edit /etc/wsl.conf, preserving existing settings, and set the correct existing username:

[user]
default=your-linux-user

Exit the shell and use wsl --terminate Ubuntu-Moved in PowerShell, then launch it again. Test your development tools, service startup, mounts and representative projects. In my migration, df -h / reported a virtual filesystem of roughly 1 TB, with ample space available. The virtual size is not a guarantee that the Windows destination drive has that much physical free space.

Once satisfied, make the new distribution the default:

wsl --set-default Ubuntu-Moved

Only when the backup is verified and the migrated copy is fully operational should you consider removing the old distribution using wsl --unregister Ubuntu. That is a destructive cleanup step, not a migration prerequisite. Keep the independent backup until you have exercised the new environment over time.

Troubleshooting permissions and PATH

I encountered an E_ACCESSDENIED error after moving the distribution. Checking and repairing access permissions on the destination resolved the issue. If that happens, confirm that the VHDX is accessible to your Windows account, that the destination filesystem is supported, and that no other process has the disk open. Avoid granting broad access to Everyone or changing system directory permissions indiscriminately.

Later, Codex appeared to disappear after a reboot. The shell was selecting a Windows npm executable under /mnt/c/Users/.../AppData/Roaming/npm/ instead of a native Linux installation. This was a PATH collision, not necessarily lost data.

type -a node npm codex
node -p 'process.platform'
printf '%s\n' "$PATH" | tr ':' '\n'

The fix was to restore a native Linux Codex installation and ensure its executable directory had appropriate PATH precedence. Before reinstalling every dependency, identify which executable the shell is actually invoking.

The takeaway

A WSL migration is manageable when the virtual disk is treated as valuable application data. Export, verify, import, test, and only then clean up. That sequence preserves a recovery path and avoids turning a disk-space problem into a development-environment rebuild.

Further reading