To backup and restore a complete WSL linux distribution, you may try to (1) create a
.tar.gz with your filesystem and (2) restore the copy using some installer tools available in the Internet:
- LxRunOffline has options to duplicate and install custom linux distributions. You may install a distro from a
- WSL-DistroLauncher allows you to install a distribution from a
- WSLInstall, another linux installer for WSL.
Creating the backup
Based on a issue report, you may create a backup using the
tar in the WSL. Note that you must ignore some folders (e.g. /mnt) in the copy.
# cd /
# tar vzcpf /mnt/c/tmp/ubuntu_`date +%Y%m%d_%H`.tar.gz --exclude=/proc --exclude=/dev --exclude=/mnt --exclude=/media --exclude=/lost+found --exclude=/tmp --exclude=/sys --exclude=/run / > /mnt/c/tmp/ubuntu_`date +%Y%m%d_%H`.log 2> /mnt/c/tmp/ubuntu_`date +%Y%m%d_%H`.error
You must create, or move later, the backup file into a valid
/mnt/c subfolder. In the example, the files are created into the
Restoring using lxRunOffline
Using lxRunOffline, you can install the resulting tar as a new distribution in WSL using the Windows command line.
# lxrunoffline install -n <distro name> -d <installation folder> -f <file>
C:\wsl> lxrunoffline install -n mybackup -d c:\wsl\mybackup -f c:\tmp\ubuntu_20180729_00.tar.gz
To run the backup, you may use the same lxRunOffline
# lxrunoffline run -n <distro name> -w
C:\wsl> lxrunoffline run -n mybackup -w
Restoring using a DistroLauncher
There are many launchers for linux distributions based on the Microsoft example. I think you may try the Yuk7 version.
You must download a distribution file and the
launcher.exe. To use the same distribution file mentioned above, you must rename the backup file to
rootfs.tar.gz and the launcher to the distribution name you want. Later you must run the launcher as an Administrator (I got errors running it as a normal user)
c:\wsl> ren launcher.exe mybackup.exe
c:\wsl> ren .\ubuntu_20180729_00.tar.gz rootfs.tar.gz
The first time you run the launcher, it installs and run the distribution. The next time, it runs the linux distribution.