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:
Options:
--version <Version>
--vhd
To see the location where virtual disks are stored, run the following from a PowerShell console window:
An example of the output from the above command is as follows:
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.
An example of the output generated by wsl -l -v is as follows:
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
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:
After import, always verify by running, wsl -l -v, which shows Ubuntu-24.04Host0 was created:
No comments :
Post a Comment