Post

Moving WSL2 File System to Another Drive

If you want to move WSL2 Linux distro(Ubuntu) from C: drive D: below are the steps.

Export Ubuntu
1
2
mkdir D:\backup
wsl --export Ubuntu D:\backup\ubuntu.tar
Unregister the same distribution to remove it from the C: drive:
1
wsl --unregister Ubuntu
Import Ubuntu
1
2
mkdir D:\wsl
wsl --import Ubuntu D:\wsl\ D:\backup\ubuntu.tar

By default Ubuntu will use root as the default user, to switch back to previous user Go to the Ubuntu App Folder run command to set default user

1
2
cd %userprofile%\AppData\Local\Microsoft\WindowsApps
ubuntu config --default-user <username>
This post is licensed under CC BY 4.0 by the author.