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

Back to top


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

Back to top

How to remove an existing WSL distro

The following syntax is used in either the PowerShell or cmd command prompt.

Arguments

Distro Name
Unique identity for each instance.

Syntax

# Syntax
wsl --unregister DistroName
# Example where Ubuntu is the Distro Name.
wsl --unregister Ubunt

Back to top

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.

Apps & features in start menu

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.

Back to top

Daniel Iser is a professional WordPress plugin developer, and the author of plugins such as Easy Modal & Popup Maker. Founder of Wizard Internet Solutions he has been working with WordPress for over 7 years creating websites and tools for clients & blog authors.

Follow on:

Leave a Comment





This site uses Akismet to reduce spam. Learn how your comment data is processed.