Moving WSL to another machine
Posted: 8 Dec 2024, 1:22am - Sunday

 In my case, I am moving from Windows 10 to Windows 11. It is my first to do this. I realised how easy I can move my work to another PC/Laptop or new machine.

In my old machine, I exported my Ubuntu by casting the command:

wsl --export Ubuntu E:\wsl\ubuntu.tar

It will take a while, mine was 150Gb for almost an hour. Then I shared my E:\wsl folder so I can easily access the file via network. Or you can copy it to USB drive.

Then go to your new machine or destination PC/laptop. First I unregister the existing Ubuntu I installed in my destination machine.

wsl --unregister Ubuntu

Then I need to import the Ubuntu I recently exported. Either you access the file remotely from your old machine or from the USB drive by casting the command:

mkdir $env:USERPROFILE\WSL\instances\Ubuntu
wsl --import Ubuntu $env:USERPROFILE\WSL\instances\Ubuntu \\OldMachine\wsl\ubuntu.tar --version 2

It will take a while again... Once done, I set it to default.

wsl --set-default Ubuntu

Then we need to set the user in the imported Ubuntu, by default will set to "root"

wsl ~
nano /etc/wsl.conf

Then add the following:

[user]
default=your_username

Save and exit. Restart WSL and when you use WSL, it should be your username.

Reference: https://askubuntu.com/questions/1429369/how-to-transfer-ubuntu-on-wsl-from-one-laptop-to-another