2

I have a SSD that went bad last weekend, and it put itself in read-only mode. I can still mount it using a rescue CD, but I can't boot into Windows 10.

I was running WSL2 on that Windows install, and I had several files living in the WSL2 filesystem. How can I access the files in the WSL2 filesystem while mounting the original drive outside of a WSL2/Windows context?

Ben Torell
  • 145
  • 6
  • You would have to take ownership of the files and export the WSL2 instance. What step of that process are you stuck on exactly? – Ramhound Dec 08 '20 at 16:41
  • I've gotten as far as finding the ext4.vhdx file and have been able to copy it to an external drive. Now I'm having trouble mounting the vhdx file. On Windows it mounts as unallocated space because it's ext4. On macOS I've tried to mount it using instructions found here: https://serverfault.com/a/1000645/43645 but I'm getting a compile error building vdfuse. On Ubuntu I've tried to mount using guestmount but the inspector just hangs. – Ben Torell Dec 08 '20 at 19:11

1 Answers1

3

This sounds hacky, I know, but I just tested it and it seems to work for me ...

  • Create a new WSL2 instance of the same distro type
  • Shut it down (wsl --terminate <distroName>, wsl --shutdown)
  • Copy your salvaged ext4.vhdx over that of the new instance's (something like C:\Users\username\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState, but you probably already know that since you found the old vhdx there anyway).
  • Cross your fingers and start up the WSL instance

My "test" scenario was slightly different, of course. When I installed my Ubuntu 20.04 WSL2 distro originally, I made a backup (wsl --export) of the "pristine" filesystem. So here, I created a new distro by doing a wsl --import of that exported tarball.

I then copied my current vhdx file over the one in the newly created instance, started it up, and all my current files were present.

NotTheDr01ds
  • 17,574
  • 4
  • 44
  • 81