First, you need to know the WSL distribution name which you want to move to another drive. List the installed WSL distributions on your computer:
# PowerShell
wsl -l -v
If you are using a username different than root
, you need to check the username:
# Linux Terminal
whoami
Shut down all the WSL distros running on Windows:
# PowerShell
wsl --shutdown
Next, you are going to create a backup for your WSL distribution Ubuntu
:
# PowerShell
mkdir D:\backup
wsl --export Ubuntu D:\backup\ubuntu.tar
Wait till the WSL export is over (it may take much time). A TAR archive with your WSL distribution file system will appear in the target directory.
When finished, you can remove the WSL distribution to free up the disk space
# PowerShell
wsl --unregister Ubuntu
Create a directory for your WSL distribution on a new drive and import the TAR archive to WSL using this command:
# PowerShell
mkdir D:\WSL
wsl --import Ubuntu D:\WSL\ D:\backup\ubuntu.tar
By default Ubuntu will use root
as the default user, to change it to another user name (we got it earlier), run:
# PowerShell
cd $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps
ubuntu config --default-user johndoe
Start the WSL distribution:
wsl -d Ubuntu