Locating WSL 2 files on a seperate Windows installation

That's going to be tricky. The D:\wsl$\ is likely a red-herring and probably was created through some side-effect by the previous user.

The location of the files (and how to back them up) for a WSL installation on that drive are going to depend on two things:

  • Whether the installation(s) was WSL1 or WSL2.
  • The distribution that was installed. While Ubuntu is, in my experience, the most common WSL distribution in use, it could be one of a number of others. It could also be more than one distribution.

The full-and-complete "right" answer (but probably overkill) would be to:

  • Run regedit, navigate to HKEY_USERS
  • File -> Load Hive, navigate to the user's Windows profile on the drive you have obtained (e.g. D:\Users\username\), and load the NTUSER.DAT in their profile directory.
  • Give the hive a name in RegEdit, something like previoususer
  • Navigate to HKEY_USERS\previoususer\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss.
  • Any subkeys there should include a BasePath with the location of the WSL files (relative to the original drive location).

But as I said, that's probably overkill.

Assuming that there was only one WSL distribution installed, and it was Ubuntu, the files will likely be in D:\Users\username\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState.

If the installation was WSL1, then the filesystem will simply be visible in that directory. Please note, while it would be okay to access these files on a defunct WSL1 install like this, accessing a live WSL1 filesystem in this way is likely to corrupt it.

If the install was WSL2, then everything is going to be in a virtual HDD named ext4.vhdx in that folder.

Accessing the files in ext4.vhdx is trickier, since Windows can't mount that virtual disk since it doesn't understand the ext4 filesystem.

You'll need to either:

  • Mount the virtual disk in a Linux system using something like this answer. Note -- This might work from your WSL2 instance, but I haven't tried it.

  • Backup an existing WSL on your Windows install with wsl --export, then create a new instance with wsl --import NewDistroName <some_directory> <the_tar_file_from_the_export> --version 2. Then copy the vhdx file from the old drive over the vhdx file in the <some_directory> location you created. Hacky, but it works.

  • Wait for the 2021H2 release of Windows 10 that will include the ability to mount these files directly into another WSL instance. Or run Windows Insider/Preview to get access to this feature now (caveat being that it is a "preview" version with known bugs).