How I backup my WSL2 VM

By jeff


I like the "idea" of Unix and the derivatives Linux and FreeBSD in particular. However, most the applications that I need to actually get work done rely on Windows.

So, when I build personal proejcts I like to build them with FreeBSD or a flavour of Linux (Like with TrueNAS or UnRaid).

But I don't like maintaining too many computers or VMs, enter WSL [1]. I've switched to WSL2 to be as close to native linux as I can, and because I like to be as close to the source without added features I install Debian.

Since I don't trust automatic backups and images built into windows (I have never successfully recovered a dead machine from an image), I want to back up my WSL2 Debian instance manually.

This has the added feature of portability. I am currently running 100% on my Framework laptop, but if in the future I need to breakout my desktop again I should be able to use these backups to just keep going.

How do I backup?

It's still a manual process, but I tend to run the backup whenever I make a major change in the configuration, or install a bunch of packages.

I follow the steps that I learned here.

The steps

Since you may not have everything set up the same as me, the first thing you need to do is figure out what distributions you have installed.

Open powershell by typing powershell in the search bar of windows.

Once you are there type:

wsl -l -v

If your instance is running you will need to shutdown before going any further. To do that type:

wsl -t Debian

Replace "Debian" above with the name of the distribtion that you are using.

Screenshot showing the WSL version and terminate commands.

Now that you know the version navigate to the folder that you want to make the save. I have a network drive mapped to A: for nostalgia purposes.

Then export the instance to a tarball by using the command:

wsl --export Debian backup-date.tar
Screenshot showing the WSL export command.

And wait till its done.