Bash, batch and PowerShell script to move WSL 2 distros VHDX file to a different location.
Use with git bash for Windows or similiar.
./move-wsl
- Select your distro
- Enter your target (i.e.
/d/wsl target/ubuntu
)
- Get a list of WSL distros:
wsl -l
- Move your image:
./move-wsl [NAME] [LOCATION]
Example: ./move-wsl docker-desktop /d/docker
Interactive way of moving wsl for Windows PowerShell.
./move-wsl.ps1
- Select your distro
- Enter your target (i.e.
D:\wsl target\ubuntu
)
This is a lightweight version which can also be used from Windows CMD.
- Get a list of WSL distros:
wsl -l
- Move your image:
move-wsl.bat [NAME] [LOCATION]
Example: move-wsl.bat docker-desktop D:\docker
Set your default user inside your distro by adding this to your /etc/wsl.conf
[user]
default=YOUR_USERNAME
Then exit your distro, terminate it (wsl -t YOUR_DISTRO
) and start it again.
Since we need to unregister to import it with the same name, the standard distro can be switched. Just set your standard distro again:
wsl -s YOUR_DISTRO
Feat: Better error handling of export by Schop0.
Fix: Replace newlines in wsl command output as it broke selection sometimes.
Feat: Added PowerShell version by sidecus.
Change: Use -q
query for more parseble output of distros.
Fix: (Default) appendix was breaking distro selection in interactive mode.
Feat: Add interactive mode for bash script.
Feat: Add validation for successfull export and import for bash and batch script.