The Windows Subsystem for Linux (WSL) allows you to create a backup (export) of your Linux distributions so you can restore (import) them in a new setup of Windows 11 or Windows 10, another computer, or when you want to share the distro with other people.
Whatever the situation might be, you can use the wsl.exe
tool with the --export
option to backup and the --import
option to restore a distribution. However, there is one caveat, when using this method, the Linux distribution (for example, Ubuntu, CentOS, Debian, Mint, etc.) will lose its integration with the Start menu, and it’ll no longer appear as an item in the “Apps & features” settings.
This guide will teach you the steps to back up and restore Linux distros installed in the Windows Subsystem for Linux 2 (WSL2) on Windows 11 and 10.
Perform backup of Linux distro on WSL
To backup a WSL Linux install on Windows 11 (or Windows 10), use these steps:
-
Open Start on Windows 11.
-
Search for Command Prompt, right-click the top result, and select the Run as administrator option.
-
Type the following command to determine the available Linux distros and press Enter:
wsl --list
-
Type the following command to create a backup of the WSL distro and press Enter:
wsl --export DISTRO-NAME PATH\FILE-NAME.tar
In the command, change DISTRO-NAME and PATH\FILE-NAME.tar with the information for your distribution. If you don’t specify a path, the backup will be stored in the root of “C:”. For example, this command backs up (exports) the Ubuntu distro:
wsl --export Ubuntu ubuntu-backup.tar
Once you complete the steps, the virtual machine will export to the root of the main system drive (C:) unless you specify another location.
These instructions only create a backup of one distro. If you have additional installations, you will need to repeat the steps.
Perform restore of Linux distro on WSL
To import a Linux distro from backup on the Window Subsystem for Linux 2, use these steps:
-
Open Start.
-
Search for Command Prompt, right-click the top result, and select the Run as administrator option.
-
Type the following command to import or restore the Linux distros from backup and press Enter:
wsl --import DISTRO-NAME INSTALL-LOCATION PATH\FILE-NAME.tar
In the command, change DISTRO-NAME, INSTALL-LOCATION, and PATH\FILE-NAME.tar with the information for your distribution. For example, this command restores (imports) the Ubuntu distro:
wsl --import Ubuntu C:\Users\USERNAME\Distros C:\ubuntu-backup.tar
Quick note: The original installation location isC:\Users\USERNAME\AppData\Local\Packages
. However, you may want to avoid this location because the restoration won’t be identical to the original. For example, you will end up with a “.vhdx” file, and the integration won’t be the same as previously mentioned. -
Type the following command to confirm the distro has been restored and press Enter:
wsl --list
-
Type the following command to launch the distro on the Windows Subsystem for Linux and press Enter:
wsl --distribution NAME-DISTRO
After you complete the steps, the distribution will import to the specified destination. The only caveat is that this backup and restore don’t have the same integration as installing the distros from the Microsoft Store. For example, once the distro is imported, it won’t register in the Start menu and won’t appear as an app you can remove from the “Apps & features” settings page.
If you want to run the distro, you’ll need to run this command: wsl --distribution DISTRO-NAME
, or you can select the distribution from the Windows Terminal menu. Also, if you want to uninstall the imported Linux virtual machine, you will need to use this command: wsl --unregister DISTRO-NAME
.