You've spent hours setting up your WSL distribution — installed the right packages, configured your shell, tuned your development environment. Now you need to experiment with something risky. Maybe a major version upgrade, a new tool that might break things, or a client project that needs its own isolated environment.
You don't want to mess up your working setup. What you want is a clone.
WSL doesn't have a --clone command, but you can achieve the same result with export and import. The idea is simple: export your distribution to a tar file, then import it as a new distribution with a different name.
How to Clone a Distribution
Step 1: Export the Source
wsl --export Ubuntu C:\Temp\ubuntu-clone.tar
This creates a complete snapshot of the distribution's filesystem. Everything is included — installed packages, user accounts, configuration files, your home directory contents.
For large distributions, this can take a few minutes and the tar file will be roughly the same size as your used disk space inside the distro.
Step 2: Import as a New Distribution
wsl --import Ubuntu-Dev "D:\WSL\Ubuntu-Dev" C:\Temp\ubuntu-clone.tar
The arguments are:
-
Ubuntu-Dev— the name for the clone -
D:\WSL\Ubuntu-Dev— where to store the clone's virtual disk -
C:\Temp\ubuntu-clone.tar— the tar file from step 1
WSL creates a new VHDX file at the specified location and extracts the tar contents into it.
Step 3: Fix the Default User
When you import from a tar archive, WSL defaults to logging in as root. You need to restore your default user.
Start the clone as root and edit /etc/wsl.conf:
wsl -d Ubuntu-Dev -u root
# Check if [user] section already exists
grep -q "^\[user\]" /etc/wsl.conf 2>/dev/null || cat >> /etc/wsl.conf << 'EOF'
[user]
default=yourusername
EOF
exit
Restart the distribution:
wsl --terminate Ubuntu-Dev
wsl -d Ubuntu-Dev
whoami
This should show your username.
Step 4: Clean Up
Delete the temporary tar file:
Remove-Item C:\Temp\ubuntu-clone.tar
Faster Cloning with VHD Format
The tar export/import works but it's slow for large distributions. The entire filesystem gets serialized to tar, then extracted back. For a 50GB distribution, that's a lot of I/O.
A faster approach uses VHD format, which copies the virtual disk directly:
# Export as VHD (much faster)
wsl --export Ubuntu C:\Temp\ubuntu-clone.vhdx --format vhd
# Import the VHD copy
wsl --import Ubuntu-Dev "D:\WSL\Ubuntu-Dev" C:\Temp\ubuntu-clone.vhdx --vhd
The VHD method skips the tar serialization entirely. It copies the VHDX file as-is, which is significantly faster and also preserves your default user settings (no need to fix /etc/wsl.conf).
Use Cases for Cloning
Testing upgrades: Clone before running do-release-upgrade on Ubuntu. If it breaks, delete the clone and try again.
Project isolation: Give each major project its own distribution with exactly the dependencies it needs. No conflicts between projects with different Node.js, Python, or library versions.
Experimentation: Want to try a new shell, desktop environment, or system configuration? Clone first, experiment freely.
Training environments: Create a pre-configured development environment, clone it for each team member or workshop participant.
Before risky changes: About to restructure your home directory, change your shell, or modify system services? A clone is your safety net.
The Easy Way: WSL UI
WSL UI has a one-click clone feature. Right-click a distribution and choose "Clone" to get a dialog where you:
- Enter a name for the clone (defaults to
DistroName-clone) - Optionally choose a custom install location
- Click Clone and wait
Behind the scenes, it exports to a temporary file in %TEMP%, imports with the new name, and cleans up automatically. It also tracks clone lineage in metadata — so you can see which distribution was cloned from which, useful when you have multiple clones and need to remember the original.
Tips
-
Choose meaningful names for clones.
Ubuntu-Dev,Ubuntu-Staging,Ubuntu-MLare better thanUbuntu-clone-2. - Put clones on a different drive if your C: drive is running low. Use the install location parameter to direct the VHDX to D: or another drive.
-
Delete clones when done. Each clone has its own VHDX file that takes real disk space. Clean up with
wsl --unregister CloneNamewhen you no longer need it. - Prefer VHD format for large distributions. It's faster and preserves user settings.
Summary
| Task | Command |
|---|---|
| Export (TAR) | wsl --export Ubuntu backup.tar |
| Export (VHD, faster) | wsl --export Ubuntu backup.vhdx --format vhd |
| Import clone (TAR) | wsl --import NewName "D:\path" backup.tar |
| Import clone (VHD) | wsl --import NewName "D:\path" backup.vhdx --vhd |
| Fix default user | Edit /etc/wsl.conf → [user] → default=username
|
| Delete clone | wsl --unregister NewName |
Cloning is one of those capabilities that changes how you work with WSL. Instead of being precious about your single distribution, you can branch off, experiment, and throw things away. Treat distributions like git branches — cheap to create, easy to discard.
Originally published at https://wsl-ui.octasoft.co.uk/blog/cloning-wsl-distributions
Top comments (0)