How to Backup Windows Subsystem for Linux distributions
I have always liked using Windows Subsystem for Linux (WSL), I’d routinely trash installs then reinstall them from the Microsoft store and have become quite adept at setting up new instances with everything I need to get back to coding as quickly as possible.
Because most of the work I do in WSL is in a git repo somewhere means I can start up again where I left off as long as I have committed and pushed my code that is!
I’ve covered getting set up with a WSL instance that isn’t on the Microsoft store before with a WSL Web Developer Bootstrap with Fedora 33.
That covered importing the distribution from a rootfs
(root file
system) image and configuring it from scratch.
This time around is for when I have a really nice setup and I’d perfer not to have to setup again I can do this instead.
List installed distros
To back up, I can get the list of installed distros in PowerShell with:
1wsl -l -v
That gives me a list of my installed distrobutions:
1NAME STATE VERSION2 Ubuntu Stopped 23 fedoraremix Stopped 24 Debian Stopped 25* Fedora-33 Running 2
The *
denotes my default distribution, so I’m going to backup the
Fedora 33 instance. First up I’ll need to navigate to where I want to
save the backup, to list all drives in PowerShell I can use the
following:
1# | FORMAT-TABLE added for less verbose output2GET-WMIOBJECT win32_logicaldisk | FORMAT-TABLE
From here I can cd
to the drive I want to save the distro:
1cd e:2# list out local directories3dir4# change to disired folder5cd .\distros\
Just to note, if I’m currently running that WSL instance it will stop! It’s best to stop WSL with:
1wsl --shutdown
Backup distro
I’ll make sure I’ve not got anything running on there before going to the next step which is the backup.
Now I can run the export and wait for it to do it’s thing:
1# Fedora-33 is the distro2# Fedora-33.tar is the backup file3wsl --export Fedora-33 Fedora-33.tar
This can take a while to complete whilst it makes the backup. I’ll go make a cup off coffee whilst I wait!
Ant that’s it, I have a backup of my Fedora 33 instance waiting for me on another drive if anything catastrophic happens.
Little tip as well if you’re in PowerShell and you want an admin level terminal you can run the following command to open a new terminal window with admin rights:
1Start-Process powershell -Verb runAs
If I want to reinstate the backup I can use the --import
command,
here I have to specify where I want it to go as well, something like
this:
1wsl --import (distribution) (where I want it to go) (path to backup)
Import backed up distro
So if I wanted to reinstate the distribution in it’s current location I can do this:
1wsl --import Fedora-test e:\distros .\Fedora-33.tar
Then if I go check available distros again with wsl -l -v
I’ll get
this:
1NAME STATE VERSION2 Ubuntu Stopped 23 fedoraremix Stopped 24 Debian Stopped 25* Fedora-33 Running 26 Fedora-test Stopped 2
Remove installed distro
Cool, cool! Now as I’m not using it I’m going to unregister it with
the --unregister
command:
1wsl --unregister Fedora-test
Back to Top