How to Back Up a WSL2 Linux Environment
In this article
You can back up a WSL2 environment by exporting the entire distribution to a single .tar file from Windows, then importing it later if you need to restore. The export captures the whole Linux filesystem, including installed packages, configuration files, and user data. You do not need to shut down Windows or use any Linux backup tool; the export command runs from PowerShell or Command Prompt on the Windows side.
What You'll Need
- Windows 10 (version 2004 or later) or Windows 11 with WSL2 installed and at least one Linux distribution registered.
- Administrator access to PowerShell or Command Prompt (you can run the commands without admin, but admin avoids permission issues on some systems).
- Enough free disk space on the target drive to hold the exported
.tarfile. The file is roughly the size of the distribution's used space, often several gigabytes. - A destination folder you can write to, such as
C:\WSL-Backupsor an external drive. Avoid network shares if the export is large, as they can time out.
Step-by-Step
- List your installed distributions. Open PowerShell (press Win+X and choose Windows PowerShell or Terminal) and run
wsl --list --verbose. Note the exact name of the distribution you want to back up (for exampleUbuntu-22.04) and confirm it is running WSL version 2. If it shows version 1, you can still export it, but the backup will be a WSL1 filesystem. - Create a backup folder. In PowerShell, run
mkdir C:\WSL-Backups(or choose another path). Make sure the drive has free space at least as large as the distribution's used space. You can check used space from inside WSL withdf -h /. - Shut down the distribution before exporting. Run
wsl --terminate <DistroName>using the name from step 1. This stops all running processes so the export captures a consistent state. You do not need to shut down all of WSL, only the distribution you are backing up. - Export the distribution. Run
wsl --export <DistroName> C:\WSL-Backups\<DistroName>-backup.tar. Replace<DistroName>with the exact name, for examplewsl --export Ubuntu-22.04 C:\WSL-Backups\Ubuntu-22.04-backup.tar. The command may take several minutes and shows no progress bar in older Windows builds; wait until the prompt returns. - Verify the backup file. Check that the
.tarfile exists and has a reasonable size:dir C:\WSL-Backups. A file of a few hundred megabytes to several gigabytes is normal. If it is 0 bytes, the export failed; check the distribution name and free space. - Store the backup safely. Copy the
.tarfile to an external drive or cloud storage. Keep at least one copy off the machine, because a disk failure would take both the original distribution and a local backup. - Restore when needed. To restore, first ensure the distribution name is not already registered (or unregister it, which deletes its data). Then run
wsl --import <NewName> C:\WSL\<NewName> C:\WSL-Backups\<DistroName>-backup.tar --version 2. The<NewName>is the name you want in WSL; it can be the same as the original if you unregistered it first. The import creates a new virtual disk from the tar file. - Set the default user after import (optional). Imported distributions start with the root user by default. To change the default user, edit
/etc/wsl.confinside the new distribution and add a[user]section withdefault=<username>, then restart WSL withwsl --shutdown. Alternatively, runwsl --manage <NewName> --set-default-user <username>if your Windows build supports it.
Common Mistakes
- Exporting while the distribution is running. Files can change during the export, producing an inconsistent backup. Always terminate the distribution first.
- Using the wrong distribution name. The name in
wsl --listis case-sensitive in some commands. Copy it exactly, including version numbers likeUbuntu-22.04. - Forgetting that
wsl --unregisterdeletes data. If you unregister a distribution to reuse its name during import, all its files are gone. Make sure the backup file is valid before unregistering. - Saving the backup inside the WSL filesystem. Exporting to a path like
/home/user/backup.taris not possible from Windows PowerShell; use a Windows path such asC:\WSL-Backups. - Assuming the backup includes Windows-side settings. The export covers the Linux filesystem only. WSL global settings in
.wslconfigand per-distribution settings inwsl.confinside the distribution are included if they are inside the Linux filesystem, but Windows-side configuration is not.
Tips
- Name backups with a date, for example
Ubuntu-22.04-2025-06-01.tar, so you can keep multiple versions. - Compress the tar file if disk space is tight. WSL exports are uncompressed tar archives; you can compress with a tool like 7-Zip after export, but you must decompress before importing.
- Test the restore process on a spare machine or after renaming the original distribution, so you know the backup works before you need it.
- For a lighter backup, copy only your project files and configuration from inside Linux using
tarorrsyncto a Windows-mounted folder. This does not capture installed packages, so a full export is safer for a complete environment. - Keep the WSL version consistent. If you export a WSL2 distribution and import it with
--version 2, it stays WSL2. Importing without the flag may default to WSL1 on older systems.
Troubleshooting
- The export command hangs or takes very long. Large distributions can take several minutes. If it seems stuck for more than 15 minutes, check free disk space and try exporting to a local drive rather than a network share.
- "The system cannot find the file specified" or "The distribution name is invalid". Run
wsl --list --verboseagain and copy the name exactly. If the distribution is not listed, it may be installed for a different Windows user. - Import fails with "The specified file is not a valid tar file". The export may have been interrupted. Delete the partial file and export again after terminating the distribution.
- The imported distribution starts as root and your files are missing. The import creates a fresh filesystem from the tar; if you imported with a new name, the old distribution still exists separately. Check that you imported the correct tar file.
- WSL commands are not recognized. Ensure the Windows Subsystem for Linux optional feature is enabled and that you are using PowerShell or Command Prompt, not a Linux shell. Run
wsl --statusto check the WSL version.
Frequently Asked Questions
Does exporting a WSL2 distribution include my installed packages and files?
Yes. The export captures the entire Linux filesystem, including installed packages, configuration files, and user home directories. It does not include Windows-side settings or files stored outside the WSL filesystem.
Can I back up a WSL2 distribution while it is running?
You can run the export command while it is running, but the backup may be inconsistent because files can change during the export. Terminate the distribution first with wsl --terminate <DistroName> for a clean snapshot.
How do I restore a backup to a different computer?
Copy the .tar file to the new computer, ensure WSL2 is installed, then run wsl --import <NewName> <InstallPath> <PathToTar> --version 2. The new computer does not need the original distribution installed.
Is the backup file compressed?
No. WSL exports are uncompressed tar archives. You can compress them with a separate tool after export, but you must decompress before importing.
What happens if I unregister a distribution before importing the backup?
Unregistering deletes the distribution and all its data from WSL. The backup tar file remains on disk and can be imported to recreate the environment, but any changes made after the export are lost.
Can I schedule automatic backups?
WSL does not have a built-in scheduled backup feature. You can create a Windows Task Scheduler task that runs the wsl --export command on a schedule, but you must ensure the distribution is terminated first or accept a potentially inconsistent snapshot.