This article discusses restoring a WSL distro from a backup TAR file. In a previous entry, the backup process for a WSL distro was presented: WSL: Backing Up and Deleting a Distro. Restoring from a backup is a bit more complicated because the wsl --import command requires that the "install location" be specified, but knowing where the default path used by WSL to install virtual disks (*.vhdx files) is important.
Microsoft documentation, Import any Linux distribution to use with WSL, presents the full wsl --import command as follows:
wsl.exe --import <Distro> <InstallLocation> <FileName> [Options]
Options:
--version <Version>
--vhd
To see the location where virtual disks are stored, run the following from a PowerShell console window:
$regKeyPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss'
Get-ChildItem $regKeyPath |
Get-ItemProperty |
Select-Object DistributionName, BasePath
An example of the output from the above command is as follows:
DistributionName BasePath
---------------- --------
docker-desktop \\?\C:\Users\jann\AppData\Local\Docker\wsl\distro
docker-desktop-data \\?\C:\Users\jann\AppData\Local\Docker\wsl\data
Ubuntu-24.04 C:\Users\jann\AppData\Local\wsl\{e3757a3a-1cb5-4208-b9c2-5f6f7490cda8}
From the above output, the default location used by WSL is:
C:\Users\jann\AppData\Local\wsl
Notice the GUID in the path, meaning WSL creates a random folder name — a GUID (e.g., {e3757a3a-1cb5-4208-b9c2-5f6f7490cda8}) — for the distro instance.
C:\Users\jann\AppData\Local\wsl\{e3757a3a-1cb5-4208-b9c2-5f6f7490cda8}
For the sake of example, the following InstallLocation could be used when importing an instance of Ubuntu-24.04:
C:\Users\jann\AppData\Local\wsl\Ubuntu-24.04Host00
The distro name must be unique so run the following comment to see the current distros installed.
wsl -l -v
An example of the output generated by wsl -l -v is as follows:
NAME STATE VERSION
* docker-desktop Stopped 2
docker-desktop-data Stopped 2
Ubuntu-24.04 Running 2
From the list of names, choosing Ubuntu-24.04 as the name for the imported distro would be invalid.
For our example, the following parameters will be used:
- Distro Ubuntu-24.04Host00
- InstallLocation: C:\Users\jann\AppData\Local\wsl\Ubuntu-24.04Host00
- FileName: C:\Backups\20250921Ubuntu-24.04.tar
In the blog,
WSL: Backing Up and Deleting a Distro, a backup TAR file named 20250921Ubuntu-22.04.tar was created. The steps described in the blog were used to create a backup of a clean Ubuntu-24.04 WSL distro and the full back up file was placed at:
C:\Backups\20250921Ubuntu-24.04.tar
The full command to import the back up is as follows:
wsl --import Ubuntu-24.04Host0 'C:\Users\jann\AppData\Local\wsl\Ubuntu-24.04Host00' 'C:\Backups\20250921Ubuntu-24.04.tar'
The import took tens of seconds compared to the export, which took minutes. Once complete, wsl --import displays status:
The operation completed successfully.
After import, always verify by running, wsl -l -v, which shows Ubuntu-24.04Host0 was created:
NAME STATE VERSION
* docker-desktop Stopped 2
Ubuntu-24.04Host0 Stopped 2
docker-desktop-data Stopped 2
Ubuntu-24.04 Stopped 2