This post shows students and new users steps to back up and restore a Linux distribution on Windows Subsystem for Linux (WSL). When use use WSL, you can backup (export) or restore (import) Linux onto another WSL system easily using the wsl.exe --export and --import command options.
For those who don’t know about WSL, here’s an overview: Windows Subsystem for Linux that lets developers run a GNU/Linux environment, including most command-line tools, utilities, and applications directly in Windows without setting up a virtual machine or dual-boot.
You can use WSL to run Linux in within Windows without the need for additional hardware or dedicated virtual machine environment. Using its export and import feature allows you to store your Linux machine securely and restore it in an event that the original is corrupted or not functioning properly.
One caveat when using the export and import method is that, the Linux machine will lose its integration with the Start menu, and no longer appear as an item in the Apps & features settings after you import it. But all other functionality will remain.
Below is how to use the export and import feature with WSL.
How to backup and restore Linux machine on WSL
As mentioned above, when use use WSL, you can backup (export) Linux or restore (input) onto another WSL system easily using the wsl.exe --export and --import command options.
To backup Linux in WSL, go to the Start menu in Windows, then search and open the Command Prompt as administrator.
Once the command prompt opens, you can list all available Linux OS in your WSL environment.
Now to backup a Linux OS named (Ubuntu-20.04), use the command format as below:
wsl --export Ubuntu-20.04 C:\Windows\Ubuntu-20.04.tar
Change the Linux machine name to the one in your environment, and also change the destination path to where you want to store the backup file.
In the example above, the destination backup location is at C:\Windows folder.
Once the file is backed up, you can restore the machine on the same WSL host or another Windows host running WSL. To restore, use the command format below.
wsl --import Ubuntu-20.04 C:\Users\<username>\Ubuntu C:\Windows\Ubuntu-20.04.tar
Change the name of the Linux machine as well as the location to restore the Linux machine. By default, Windows store Linux machines in the following location:
If you want to restore the machine at the default location, simply use the default location instead.
That should do it! However, when you export and restore a Linux machine using the steps above, it won’t have the same integration as installing the distros from the Microsoft Store. It won’t register in the Start menu, or appear as an app in the Apps & features settings page.
This post showed you how to back up and restore Linux machine running in WSL environment on Windows host. If you find any error above or have something to add, please use the comment form below.