WSL2 Backup and Restore
Prerequisites
wsl --list
Result:
Windows Subsystem for Linux Distributions:
Ubuntu20.04LTS (Default)
Debian
We will work with Ubuntu20.04LTS
Shutwown WSL
wsl --shutdown
Export (Backup) image
Template:
wsl --export <Image Name> <Path to exportable .tar image file>
An actual command in my case:
wsl --export Ubuntu20.04LTS c:\back\Ubuntu20.04LTS.tar
Import (Restore) image
Import image
Template:
wsl --import <Image Name> <Directory where you want to store the imported image> <Path to exported .tar image file>
An actual command in my case:
wsl --import Ubuntu20.04LTS c:\WSL_Dir_With_Read_Write_Permissions\Ubuntu20.04LTS c:\back\Ubuntu20.04LTS.tar
Distro will be started automatically with a root prompt
Set default user
- Execute
awk -F: '/\/home/ {printf "%s:%s\n",$1,$3}' /etc/passwd
and find decimal ID of required user.1000
in my case (linemy_user_name:1000
) - Enter
exit
command - Ensure you are in CMD without Admin privileges and execute
wsl --shutdown
command - Launch 'regedit'
- Go to
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss
- Find your distro ID and go to an appropriate subkey
- Ensure value of name 'DefaultUid' and of type 'REG_DWORD' with value data
1000
with base Decimal - Close Regedit
Set default distro
wsl --setdefault Ubuntu20.04LTS
wsl --shutdown
Start WSL:
wsl
Ubuntu 20.04 LTS will start with your chosen user prompt