Skip to content
WSLHow-To Published Updated 5 min readViews unavailable

How to Back Up and Restore a WSL Distro

Exporting a WSL distro's entire state to a portable file, and restoring it later on the same machine after a problem or on an entirely different one.

Because a WSL distro is fundamentally just a filesystem tarball plus registration metadata, backing one up completely and restoring it later is straightforward — this walks through doing it properly.

Step 1: identify the distro you want to back up

wsl --list --verbose

Step 2: export the distro to a tar file

wsl --export Ubuntu C:\Backups\ubuntu-backup.tar

This captures the distro’s entire current filesystem state — installed packages, configuration files, home directory contents, everything — into a single portable file.

Step 3: verify the export completed successfully

dir C:\Backups\ubuntu-backup.tar

Check the file size looks reasonable given your distro’s actual disk usage — a suspiciously small file may indicate the export didn’t complete fully.

Step 4: restore to a new distro instance (same or different machine)

wsl --import UbuntuRestored C:\WSL\UbuntuRestored C:\Backups\ubuntu-backup.tar

This creates a genuinely new, independent distro instance from the backup file — on the same machine as a parallel copy, or copied to a different machine entirely and imported there.

Step 5: set the default user for the restored distro

wsl -d UbuntuRestored -u root
# from inside: edit /etc/wsl.conf to set default user, or use:
ubuntu config --default-user yourusername

Export/import preserves the filesystem completely but doesn’t always automatically preserve the original default-user setting — this is worth checking and resetting after import if you land in a root shell unexpectedly.

Step 6: verify the restored distro works as expected

# from inside the restored distro:
ls ~
apt list --installed | head

Confirming your files and installed packages are present as expected verifies the restore actually captured everything you needed.

Step 7: replace an existing distro with a restored backup, if needed

wsl --unregister Ubuntu
wsl --import Ubuntu C:\WSL\Ubuntu C:\Backups\ubuntu-backup.tar

--unregister permanently deletes the current distro’s filesystem — only do this after confirming your backup file is good, ideally by test-importing it under a different temporary name first per Step 4.

Step 8: set up a regular backup schedule for anything you can’t afford to lose

# a scheduled task running wsl --export periodically,
# or simply a manual habit before any risky change
# (a major update, a distro upgrade)

Running an export before attempting anything with real risk of leaving a distro in a broken state — a risky system update, testing an unfamiliar configuration change — gives you a clean rollback point at minimal cost.

Step 9: move a distro to a different drive using the same mechanism

wsl --export Ubuntu D:\temp-export.tar
wsl --unregister Ubuntu
wsl --import Ubuntu D:\WSL\Ubuntu D:\temp-export.tar

Export/import is also the standard way to relocate a distro’s storage to a different physical drive, since the --import command lets you specify exactly where the new virtual disk should be created.

Why this simple mechanism is more reliable than ad hoc file copying

Because export/import operates on the distro as a complete, coherent unit — rather than trying to selectively copy files while leaving out running processes, mounts, or partial state — it produces a genuinely complete, consistent backup every time, without needing to reason carefully about which specific files or directories matter enough to include.

Quiescing databases and running services before exporting

A distro export captures whatever is on disk at that exact moment, which means an actively-writing database or service can end up in an inconsistent state inside the backup even though the export command itself completes without error. Stopping the relevant service, or better, using its own native dump/checkpoint command, before running the export produces a genuinely restorable backup rather than one that merely looks complete. This distinction matters enough that it’s covered in more depth in this blog’s dedicated piece on backup consistency.

Recording metadata alongside every backup

Beyond the tar file itself, note the distro name, the WSL version in use, the date, and ideally a checksum of the resulting file:

sha256sum ubuntu-backup.tar > ubuntu-backup.tar.sha256

This lets you confirm later that the specific backup file wasn’t corrupted or altered before trusting it during an actual, possibly stressful recovery situation.

Testing a restore before you actually need one

The only way to know a backup genuinely works is restoring it — under a temporary, clearly-named distro instance, well before an actual emergency, following through to confirming your applications and data are genuinely intact rather than just confirming the wsl --import command itself completed without error.

Choosing between tar and a direct VHDX export

Newer WSL versions can export directly to a .vhdx file instead of a tar archive, skipping a repack step at the cost of tying the backup more closely to WSL’s own virtual-disk tooling. Tar remains the more broadly portable choice when you’re not certain what you’ll restore it with later; a direct VHDX export is worth using when speed matters and you know the restore path will also be WSL-based.

Keeping more than one backup generation around

A single most-recent export is better than nothing, but it means a corruption discovered days after the fact has no earlier, still-good copy to fall back to. Rotating at least two or three dated exports — deleting only the oldest once a new one is confirmed good — costs modest disk space in exchange for a genuinely useful safety margin against a backup that turns out to have captured a problem already in progress.

Related:

Sources:

Comments