Readers like you help support XDA Developers. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.

Taking regular backups of your computer is a smart thing to do. Whether you use Windows, Mac, Linux, or Chrome OS, you can never be too careful. The same applies to the Windows Subsystem for Linux (WSL) which runs on top of but is somewhat independent of Windows.

WSL instances are easy to set up, but without a backup, you'll have to redo everything manually if something goes wrong. WSL backups are also an easy way to transfer your environment between machines.

Fortunately, it's a very straightforward process to back up a Linux distro (distribution) on WSL, as well as restore it if you need to.

How to back up a Windows Subsystem for Linux (WSL) distro

Screenshot of Windows Terminal backing up a WSL distro

As WSL isn't Linux running on bare metal, we don't need to do anything within the distro itself to instigate a backup. Instead, the operation is entirely run from PowerShell. Here's what you need to do:

  1. Open Windows Terminal into a PowerShell profile (it should be the default behavior).
  2. Run the command wsl -l -v inside PowerShell to print a list of all currently installed Linux distros. It's important that you know the exact name to create a backup. For example, you may have Ubuntu-22.04 rather than just Ubuntu.
    Screenshot of Windows Terminal showing a list of WSL distros installed
  3. Choose a directory you want to save your backup to. In the PowerShell window, enter cd (directory), replacing (directory) with the path where you want to store the backup file. For example, we're choosing a folder called WSL backups in our Documents library, so we'll enter this command:
    cd "C:\Users\joaoc\Documents\WSL backups"
  4. Enter the following command to export the distribution:
     wsl --export (distribution) (filename.tar) 
    • You'll need to replace (distribution) with the name of the distro you want to export, and filename with whatever you want the backup file to be called. For example, to back up Ubuntu would look something like this:
       wsl --export Ubuntu Ubuntubackup.tar
  5. Alternatively, instead of using cd to get into the correct directory, you can specify the file location and filename as part of the export process. For example:
     wsl --export Ubuntu C:\Users\joaoc\Documents\WSL backups\Ubuntubackup.tar 

That's it for the backup process. The file you have now created can be used either on that same PC or another one to set up an exact copy of your Linux distro. You do this using the import command in Powershell.

How to import a WSL distro from a backup

Screenshot of Windows Terminal with a command to import a backed up WSL distro

If you're exporting your Linux distro, you probably want to restore it at some point. In WSL, that is accomplished using the import command. If you're using it on the same PC, we're assuming you have already used the --degregister command to remove your current instance. If you still have it installed, importing from a backup won't overwrite, and using the same distro name will create a conflict.

It's a little longer than the export command, as you need to specify where you want it to install as well as the file you want to use. The import command follows this template:

 wsl --import (distribution) (install location) (file path) 

So using the example export in step 5 above, you would end up with something like this:

 wsl --import Ubuntu c:\wsl c:\users\richard\desktop\ubuntumay27.tar 

After a moment, your distro will be installed and ready to go. The beauty of using export and import is that you can have the same environment set up on multiple machines in a matter of moments. Your users and passwords will be retained, as will anything you installed through the package manager.

If you want to confirm it is installed correctly before closing the PowerShell window, simply run wsl -l -v again and you should see your newly imported distro.