I copied the VHDX file (called ext4.vhdx as usual) for a WSL2 instance to a new machine. How can I use this for a new WSL2 instance?
- 28,025
- 766
1 Answers
Short answer:
wsl --import-in-place <new_distro_name> <path_to_vhdx>
More detail:
I've rewritten this answer for the latest version of WSL, since it is now available for (most) Windows 10 and (all) Windows 11 users. If you are on an earlier version of WSL and can't upgrade for some reason, then please see the edit history of this answer for an older method that you can try.
First, make sure you are on WSL 1.0.0 or later. You can install it from the Microsoft Store. Windows 10 users, see this answer for instructions on how to install the prerequisites. It's an unrelated question, but it also requires a recent WSL release.
With 1.0.0 or later in place, to reuse a ext4.vhdx on a new computer:
Place your
ext4.vhdxin the directory you want to use for the distribution. For instance,C:\Users\<youruser>\WSL\ubuntu_22.04. The name of the directory doesn't matter here.From PowerShell:
wsl --import-in-place <new_distro_name> <path_to_vhdx> # For example # wsl --import-in-place ubuntu_22.04 C:\Users\ntd\WSL\ubuntu_22.04Important: To avoid "confusing" the distribution installers, I recommend avoiding the distribution names that they would use. Examples of this include:
- Ubuntu
- Ubuntu-20.04
- Debian
- Alpine
This is why I use
ubuntu_22.04as an example, with the underscore in place of the hyphen.Follow the instructions here for setting the default username in this new distribution/instance.
Optionally, use
wsl --set-default <distro>to set the imported distribution as the default that will run when you just executewsl. If this is the only distribution, it should automatically be set as default.
- 28,025