Moving a WSL2 distribution
By default, any Linux distribution installed in WSL2 is located on your c: drive as a .vhdx file (Virtual Hard Drive file for Hyper-V). The safest way to move this file, as far as I can tell, is to use the import/export feature of wsl2.
- Export the entire disk to a .tar file. This operation can take a minute, without any feedback.
wsl --export DistroName filename.tar - Now import the .tar file to a new distro name and location:
wsl --import NewDistroName X:\NewPath filename.tar - Remove the old distribution, freeing up the space, by running:
wsl --unregister DistroName
Now when starting the new distro, if you get logged in as root instead of the expected user, you probably want to change the default user. This can be done by editing /etc/wsl.conf inside the distribution:
[user]
default=username
References: https://github.com/MicrosoftDocs/WSL/issues/412 https://github.com/microsoft/WSL/issues/4276