How to access WSL2 filesystem when mounting the drive that the WSL2 filesystem lives on?

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error How to access WSL2 filesystem when mounting the drive that the WSL2 filesystem lives on? on this date .

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?

Answer

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:UsersusernameAppDataLocalPackagesCanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgscLocalState, 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.