It's always a good idea to back up your PC occasionally. You never know when something will go wrong, so whether you're using Linux, Windows 11, or macOS, regular backups are a good thing. And if you're using the Windows Subsystem for Linux (WSL), it's also a good idea to back up your Linux instances.

Backing up WSL instances is very easy, and it can save you some time setting up WSL on a new PC or if you've reset your laptop and want to get back to a working state quickly.

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

Since the Windows Subsystem for Linux is kind of like a virtual machine, backing up your data actually doesn't require you to do anything in Linux itself. All you need to use is Windows Terminal (or Windows PowerShell).

  1. Open Windows Terminal into a PowerShell profile (it should be the default behavior).
  2. Run the command below 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.
    wsl -l -v
    Screenshot of Windows Terminal displaying a list of installed Linux distros
  3. To export a distribution, use the following command, replacing (distribution) and (file path) with the name of the distribution you want to backup and the path where you want to store the backup, respectively.
    wsl --export (distribution) (file path)
    Replacing the placeholders with the correct information, you'll get something like this:
    wsl --export Ubuntu "C:\Users\joaoc\Documents\Linux backups\ubuntubackup.tar"
    Screenshot of Windows Terminal exporting a WSL distribution
  4. Wait a few minutes for the backup to finish.

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

If you're exporting your Linux distro, you probably want to restore it at some point. You can do this on any PC that already has WSL installed, but it can't have that same distro set up yet. If you're trying to restore it on the same PC, you have to use the wsl --unregister command to remove the current data for that distro before importing.

To import your Linux backup, you'll need to use the following command, replacing (distribution), (install location), and (file path) with the respective information.

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

So, using the same information we used for the import, the command would look like this:

wsl --import Ubuntu "C:\Linux" "C:\Users\joaoc\Documents\Linux backups\ubuntubackup.tar"

Screenshot of Windows Terminal importing a WSL backup

After a moment, your distro will be restored, though keep in mind, this won't add the distro to your Start menu. You can launch it from the Windows Terminal using the following command, replacing (distribution) with the name of the distro you want to launch.

wsl --distribution (distribution)

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.

Wrapping up

That's all there is to backing up and importing your Linux distros in WSL. It's a relatively painless process, as long as you don't care very much about launching Linux from the Start menu. You can try installing your distro from the Microsoft Store to have it appear on the Start menu, though this might cause some issues.