
Importing & Exporting WSL Linux Distros
I regularly find myself working in WSL terminals, and often for completely different needs. This led me to find the following ways to clone and restore clean images very quickly anytime the need arises.
How to export a WSL distro image

Exporting a WSL distro is a fantastic way to back it up, clone it, share it or just about anything else you can think of. Use the following commands to do it quickly from the PowerShell or Command Prompt terminals.
Arguments
- Distro Name
- Unique identity for each instance.
- Distro File
- Path and file name for the image that will be exported.
Syntax
# Syntax wsl --export DistroName DistroFile # Example where Ubuntu is the Distro Name and exporting the Ubuntu-20.04--Clean.tar image. wsl --export Ubuntu D:\WSL\Ubuntu-20.04--Clean.tar
How to import WSL distro image

Importing WSL distributions from tar image files is extremely fast & simple. Use the following commands to do it quickly from the PowerShell or Command Prompt terminals.
Arguments
- Distro Name
- Unique identity for each instance.
- Install Path
- Path to store the VM disk image.
- Distro File
- A tar file containing the distro image.
Syntax
# Syntax wsl --import DistroName InstallPath DistroFile # Example where Ubuntu is the Distro Name, we are storing it in D:\Ubuntu folder and importing the Ubuntu-20.04.tar image. wsl --import Ubuntu D:\Ubuntu D:\WSL\Ubuntu-20.04.tar
Note: There is a known issue when importing a WSL distro in that it will not properly log in to your user account by default. The fix is simple enough.
Run sudo nano /etc/wsl.conf
to edit the WSL config file. Add the following and change the username to match your own.
[user]
default=username
Reset an existing WSL distribution
Resetting a distribution is a bit different as you don’t use the command line.
1. Open the Start Menu and search for Apps & features.

2. Search for your distro in the list, click it and choose the Advanced options link.

3. Scroll down and click the Reset button. The next time you run your WSL terminal for that distribution it will be a clean distro.


I am a founder & CEO of Code Atlantic and I've been working with WordPress for over 15 years creating plugins to help WP site owners grow for more than 10 of those. We have developed and maintained popular plugins including the best wordpress popup plugin, Popup Maker with over 4k 5 star reviews, as well as Content Control, Ahoy & User Menus.