Recently I received a new company laptop, so among other things I wanted to migrate my existing WSL installation with Ubuntu 22.04. I didn’t want to reinstall and reconfigure all the software in the virtual machine, so I looked for ways to migrate the entire system.
Here’s the process, you will find out it’s very straightforward!
On the old computer
I check which WSL installations I have, listing them with this command:
PS C:\Users\user> wsl --list Windows Subsystem for Linux Distributions: Ubuntu-22.04 (Default)
Here’s my only subsystem. You may have more, in this case the procedure can be repeated for each of them. I can export it using this command:
wsl --export --vhd Ubuntu-22.04 ubuntu-export.vhdx
The -whd switch is followed by the distribution name I identified before, followed by a name I chose for the virtual disk that is created.
The duration of the process will depend on the size of the distribution disk and the speed of the computer, in my laptop it only took 10 seconds to create a file of 2.8 GB.
The last step on the old machine is to move this file into the new machine, via network or usb disk.
On the new computer
I first install WSL. Since Windows 11 22H2, wsl can be installed without any distribution, and that’s what I’ll do. In this way, I don’t have to delete a distribution I don’t need:
PS C:\Users\ldelloca> wsl --install --no-distribution Downloading: Windows Subsystem for Linux 2.4.13 Installing: Windows Subsystem for Linux 2.4.13 Windows Subsystem for Linux 2.4.13 has been installed. Installing Windows optional component: VirtualMachinePlatform Deployment Image Servicing and Management tool Version: 10.0.26100.1150 Image Version: 10.0.26100.3775 Enabling feature(s) [==========================100.0%==========================] The operation completed successfully. The requested operation is successful. Changes will not be effective until the system is rebooted.
After the reboot, I import the exported distribution:
wsl --import-in-place Ubuntu-22.04 ubuntu-export.vhdx
This command takes just a few seconds.
Now, I can launch my Ubuntu subsystem in my new laptop: