Back-up and restore a Linux distro in WSL2
If you need to upgrade a Windows machine, set-up a new PC or restore a broken system, there’s a fairly straightforward method for backing-up and restoring WSL distros.
Windows Subsystem for Linux (WSL) allows users to run a complete Linux environment on their Windows machines. The installation of WSL is managed via Windows Powershell (PS).
Here is a list of useful commands for backing-up and restoring WSL:
- Check which distros you have installed
- Make a backup of a WSL distro
- Restore a WSL distro from a backup
Check which Linux distros you have installed
To generate a list of installed Linux distributions in WSL, open PowerShell and enter the following command.
wsl -l -v
Make a backup of a WSL distro
Backups of WSL distros are stored as .tar files. To backup a distro, you need to use the wsl --export command, which is followed by:
- The name of the distro that you want to save.
- The path to the .tar file that you will create.
wsl --export Ubuntu-20.04 c:\users\adamdimech\UbuntuBackup.tar
Restore a WSL distro from a backup
To restore a WSL distro from a back-up, use the wsl –import command in PS followed by:
- The name for the distro (you can change this from the original).
- The location for installation (the Linux file system is stored in a VHDX [virtual hard drive]).
- The path to the .tar backup file.
wsl --import Ubuntu-22.04 D:\wsl2 D:\wsl_backups\Ubuntu_22_04.tar
When a WSL distro is installed from a backup, the default user will be root. If you want to change this (or restore the default username to what it was), use the wsl --manage in PS followed by:
- The name of the distro.
- The
--set-default-usercommand and the username.
wsl --manage Ubuntu-22.04 --set-default-user adamdimech
Comments
No comments have yet been submitted. Be the first!