Config Server Firewall

How to Clone a WSL 2 Distro (Backup and Restore)

In this tutorial, you will learn how to clone a Linux distribution on Windows Subsystem for Linux 2, which can be useful for creating backups, testing changes, or transferring your environment to another machine.

Click here for instructions on installing WSL 2 if you haven't already.

In WSL 2, we use the wsl command to manage Linux distributions. Currently, the wsl command does not directly offer a cloning option for Linux distros. However, there is a simple workaround.

To clone a Linux distribution, first back up the desired distro using the --export option. Then, import the backup to launch a new distro using the --import option. This technique can also be used to migrate a WSL 2 distro from one computer to another.

Command syntax to export WSL 2 distro:

wsl --export <Distro-Name> <File-Name>

Command syntax to import WSL 2 distro:

wsl  --import <Distro-Name> <Install-Location> <File-Name>

Demo

For example, the following command exports a distro named Ubuntu to a tar file called Ubuntu.tar.gz and saves it on the c:\wsl directory:

wsl --export Ubuntu C:\wsl\Ubuntu.tar.gz

Now, to create a clone, we run the following command:

wsl --import Ubuntu-Clone c:\wsl\Ubuntu-Clone c:\wsl\Ubuntu.tar.gz

The above command creates a new distro called Ubuntu-Clone from the Ubuntu.tar.gz file. The new distro is installed on the C:\wsl directory.

And that's how we clone a Linux distribution in Windows Subsystem for Linux using the wsl --export and wsl --import commands.

We have a single Ubuntu distribution running on WSL 2.
We have a single Ubuntu distribution running on WSL 2.
Use wsl --export to create a tar file backup of your WSL distribution.
Use wsl --export to create a tar file backup of your WSL distribution.
The backup file has been created and saved to the specified location.
The backup file has been created and saved to the specified location.
Launch a new instance of the distro using the backup file.
Launch a new instance of the distro using the backup file.
We successfully cloned the original one.
We are now running two Ubuntu distributions! We successfully cloned the original one.
Click here if you'd like to learn more about using the wsl command.