Back Up and Import a WSL2 Distribution Safely
The WSL command-line tools can export a distribution to an archive and import it at a chosen install path. This walkthrough keeps the source registered while you import and test a second copy on another drive. It uses a TAR archive and imports the copy as WSL 2; retain the export until the new copy is verified.
Identify the Distribution and Record Its User
PreflightUse the exact distribution name shown by WSL. Record whether it is version 2 and the Linux username you normally use; an imported distribution commonly defaults to root, unless its preserved /etc/wsl.conf already sets a valid default user.
wsl --statuswsl --list --verbosewsl --distribution 'Ubuntu-24.04' --exec id --name --user❯ Illustrative Output (Results Vary)
NAME STATE VERSIONUbuntu-24.04 Stopped 2Stop the Source Distribution
Consistent ExportFirst take application-native backups where needed and stop databases and other stateful applications through their documented graceful shutdown procedure. Then terminate the selected distribution so applications cannot write while you export it. Termination alone does not guarantee an application-consistent backup. wsl —terminate stops only that named distribution; wsl —shutdown stops all running WSL distributions and is not needed for this procedure.
wsl --terminate 'Ubuntu-24.04'if ($LASTEXITCODE -ne 0) { throw 'WSL termination failed; stop.' }wsl --list --verbose❯ Illustrative Output (Results Vary)
Confirm Ubuntu-24.04 is no longer listed as running before exporting.Export the Distribution to a Backup Archive
BackupChoose a destination with enough free space, preferably on a separate drive from the WSL install. The standard export format is TAR. Check that the archive exists and record its size and hash before importing it.
$archivePath = 'D:\WSL-Backups\Ubuntu-24.04.tar'if (Test-Path -LiteralPath $archivePath) { throw 'Archive already exists; choose a new filename.' }New-Item -ItemType Directory -Path 'D:\WSL-Backups' -Force -ErrorAction Stopwsl --export 'Ubuntu-24.04' $archivePathif ($LASTEXITCODE -ne 0) { throw 'Export failed; do not import the incomplete archive.' }$archive = Get-Item -LiteralPath $archivePath -ErrorAction Stopif ($archive.Length -eq 0) { throw 'Export is empty; stop.' }$archive | Select-Object FullName, LengthGet-FileHash 'D:\WSL-Backups\Ubuntu-24.04.tar' -Algorithm SHA256❯ Illustrative Output (Results Vary)
Confirm export completed and the archive has a nonzero size and recorded SHA256 hash.Import a Separate Copy to the New Drive
Migration CopyPick a new registration name that is not already in wsl —list —quiet. The install location is a Windows directory where WSL can store the distribution. Importing the archive creates a second distribution; it does not overwrite or move the source.
$newName = 'Ubuntu-24.04-Moved'$installPath = 'D:\WSL\Ubuntu-24.04-Moved'$registeredNames = @(wsl --list --quiet) | ForEach-Object { ($_ -replace "`0", '').Trim() }if ($LASTEXITCODE -ne 0) { throw 'Could not list distributions; stop.' }if ($registeredNames -contains $newName) { throw 'Registration name already exists; stop.' }if (Test-Path -LiteralPath $installPath) { throw 'Install path already exists; choose a fresh path.' }New-Item -ItemType Directory -Path $installPath -ErrorAction Stopwsl --import $newName ` $installPath ` $archivePath ` --version 2if ($LASTEXITCODE -ne 0) { throw 'Import failed; keep the source and archive.' }wsl --list --verbose❯ Illustrative Output (Results Vary)
Ubuntu-24.04-Moved appears in the distribution list with VERSION 2.Restore the Default Linux User
Imported Distro SetupCheck the imported distribution’s default user first; a preserved [user] setting may already select the correct account. Open the imported copy as root, inspect any existing /etc/wsl.conf, and add or update the [user] section with the username recorded in Step 1. Preserve any other settings already in the file.
wsl --distribution 'Ubuntu-24.04-Moved' --user rootIn the Linux shell, verify the user exists and edit the per-distribution configuration:
getent passwd your_linux_usercat /etc/wsl.confvi /etc/wsl.confEnsure the file contains this section, merging it with existing content rather than replacing other sections:
[user]default=your_linux_userType exit to leave the Linux shell. Then, in PowerShell, restart the imported distribution and check the default user:
wsl --terminate 'Ubuntu-24.04-Moved'wsl --distribution 'Ubuntu-24.04-Moved' --exec id --name --user❯ Illustrative Output (Results Vary)
The final id --user output should be the Linux account you configured, not root.Verify the Copy Before Cleaning Up
Recovery CheckCheck the imported distro’s user, important files, installed applications, services, and mounts. Compare the archive hash with the recorded value. Keep the original and archive until you have tested the workloads you rely on and have a separate backup policy for the destination copy.
wsl --distribution 'Ubuntu-24.04-Moved' --exec bash -lc 'id && df -h / && test -d "$HOME"'if ($LASTEXITCODE -ne 0) { throw 'Imported filesystem check failed; investigate before cleanup.' }Get-FileHash 'D:\WSL-Backups\Ubuntu-24.04.tar' -Algorithm SHA256wsl --list --verbose❯ Illustrative Output (Results Vary)
Confirm the expected account, filesystem, files, applications, and WSL 2 registration.