I wrote this guide because I searched forever and couldn’t find a solution that I was needing; I even asked ChatGPT and Microsoft Copilot – both weren’t nearly as helpful – alas it could have also been my prompt. Anyway, I digress.
This guide helps with copying data from one Linux distro running in WSL to another Linux distro.
I was running Windows 10 and started testing out WSL in the early days of development using WSL and Ubuntu 18.04. As WSL grew in popularity and has matured, it seems like MS has baked in better ways to distribute and download Linux distros on Windows.
Fast forward to this year when I decided to upgrade to Windows 11, only realizing after the fact that I now have to manage Ubuntu through MS Store and didn’t seem like a straightforward way to migrate data between the two. For context: I had already installed the latest Ubuntu from the Microsoft Store and didn’t want to completely erase what I set up. In short, I needed a way to migrate data from my older Ubuntu installation to the new one. Okay, enough talking, let’s dive in.
Using the details below, I was able to migrate my crucial data from my source distro to my destination distro.
Source: Ubuntu 18.04
Destination: Ubuntu 22.04
The path to where your distros are stored look like the following. Remember to replace [USER]
, [DISTRO]
and [DRIVE]
with your own.
C:\Users[USER]\AppData\Local\Packages[DISTRO]\LocalState\[DRIVE]
Steps
- Start Windows PowerShell as an Administrator
- Run the following commands.
- The
wsl --mount
command makes it so that the drive shows up the devices list when runningsudo lsblk
.
- The
# lists out all Linux-based distributions installed on Windows wsl -l --all # Shutdown all WSL distros wsl --shutdown wsl --mount 'C:\Users\USER\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx' --vhd --bare
After entering those, you should see “Successfully completed” message in your PowerShell terminal.
Next, start up the distro that you want to transfer files to (in my case Ubuntu 22.04) and run commands to mount the device to a custom directory of your choosing on your destination. You’ll need to replace /mnt/ubuntu18
and /dev/sdc
to match your own set up.
sudo mkdir /mnt/ubuntu18 sudo mount /dev/sdc /mnt/ubuntu18
Voila! You should now see your virtual drive mounted inside your destination. From there, you can use the copy tool of your choice (I chose rsync
) to copy over your contents.