Skip to content

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.

01

Identify the Distribution and Record Its User

Preflight

Use 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.

Terminal window
wsl --status
wsl --list --verbose
wsl --distribution 'Ubuntu-24.04' --exec id --name --user
❯ Illustrative Output (Results Vary)
NAME STATE VERSION
Ubuntu-24.04 Stopped 2

02

Stop the Source Distribution

Consistent Export

First 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.

Terminal window
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.

03

Export the Distribution to a Backup Archive

Backup

Choose 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.

Terminal window
$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 Stop
wsl --export 'Ubuntu-24.04' $archivePath
if ($LASTEXITCODE -ne 0) { throw 'Export failed; do not import the incomplete archive.' }
$archive = Get-Item -LiteralPath $archivePath -ErrorAction Stop
if ($archive.Length -eq 0) { throw 'Export is empty; stop.' }
$archive | Select-Object FullName, Length
Get-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.

04

Import a Separate Copy to the New Drive

Migration Copy

Pick 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.

Terminal window
$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 Stop
wsl --import $newName `
$installPath `
$archivePath `
--version 2
if ($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.

05

Restore the Default Linux User

Imported Distro Setup

Check 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.

Terminal window
wsl --distribution 'Ubuntu-24.04-Moved' --user root

In the Linux shell, verify the user exists and edit the per-distribution configuration:

Terminal window
getent passwd your_linux_user
cat /etc/wsl.conf
vi /etc/wsl.conf

Ensure the file contains this section, merging it with existing content rather than replacing other sections:

[user]
default=your_linux_user

Type exit to leave the Linux shell. Then, in PowerShell, restart the imported distribution and check the default user:

Terminal window
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.

06

Verify the Copy Before Cleaning Up

Recovery Check

Check 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.

Terminal window
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 SHA256
wsl --list --verbose
❯ Illustrative Output (Results Vary)
Confirm the expected account, filesystem, files, applications, and WSL 2 registration.

Comments