To Nha Notes | May 21, 2022, 7:25 p.m.
Take benefits of export/import function of WSL to move WSL from drive C to drive D
To list the distros installed, run the following command:
wsl --list
Backup distros displayed from above command to differnece dis
wsl.exe --export Ubuntu-18.04 D:\backups\ubuntu1804\ubuntu-20220521.tar
When finish, we need to to unregister the linux distribution from C: drive. It will also release the disk space taken by WSL.
⚠️ Beware that everything that was stored on the WSL drive will be lost, and the command won't ask for a confirmation, so make sure you backup everything you need first!
wsl --unregister Ubuntu-18.04
Restore backup file to target folder of expected drive:
wsl --import Ubuntu-18.04 D:\WSL D:\backups\ubuntu1804\ubuntu-20220521.tar
When below error happended, we can fix it by below command:
wsl --unregister Ubuntu-18.04
Installing, this may take a few minutes... WslRegisterDistribution failed with error: 0x8000000d Error: 0x8000000d An illegal state change was requested.
https://dev.to/equiman/move-wsl-file-system-to-another-drive-2a3d
https://www.virtualizationhowto.com/2021/01/wsl2-backup-and-restore-images-using-import-and-export/