1

The background

  • My Windows 10 laptop, with a bad battery, lost power during boot, and now cannot successfully boot windows (it tries to fix this with the Automatic Repair utility during startup, but fails every time).
  • I want to boot the laptop into a Ubuntu live environment from a USB stick, and copy some files over from WSL distro to my USB stick.

The problem

  • While I can access my Windows drive and all of my normal Windows files from my Ubuntu live USB, I can't seem to find any of my WSL files.

The Question

  • It seems like I should be able run a command like find . -type d -name "my-directory-in-wsl" and figure out where WSL files live on my drive. I have tried this with no success. Should this work, or do WSL files live outside of the normal filesystem? Is there any hope for recovering these files?
3
  • WSL Files tend to be well hidden. Try this: Where are WSL files stored? WSL files are exposed through a network share \\wsl$[distro name], for example my home directory is at \\wsl$\Ubuntu-20.04\home\pawelb. C:\Users\pawelb\AppData\Local\Packages\CanonicalGroupLimited. ....... solidstudio.io/blog/windows-subsystem-for-linux-explained
    – anon
    Commented Sep 8, 2023 at 16:17
  • 2
    If you are using WSL2 then your files aren't directly on NTFS filesystem but inside the virtual drive VHD file placed in %PROFILE%\AppData\Local\Packages\<distro package>\LocalState\ext4.vhdx.
    – blami
    Commented Sep 8, 2023 at 16:18
  • Was erroneously closed as a duplicate, which it wasn't because in this case the user is asking how to recover files from within a Ubuntu Live USB boot, not a Windows system. Commented Sep 12, 2023 at 19:51

1 Answer 1

2

If you are using WSL2 (assumed, since you should find the WSL1 files on the drive with that search), then the entire filesystem for your WSL distribution is in a virtual SDD. As @blami mentioned in the comments, you'll find that in:

%PROFILE%\AppData\Local\Packages\<distro package>\LocalState\ext4.vhdx

For Ubuntu (the default), the package name will start with "Canonical". So something like:

OldDriveLetter:\Users\<your_old_username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx

You can also search in OldDriveLetter:\Users\<your_old_username>\AppData\Local\Packages for any ext4.vhdx files.

Copy the ext4.vhdx file off to your USB drive.

As for recovering, the safest/best way would be to use another Windows system with the latest WSL installed and:

  1. Copy the ext4.vhdx back to a location on the Windows system (preferred over trying to access it from the USB drive). For the sake of the example below, we'll assume it's placed in C:\WSL\instances\Recovered.

  2. Import the distribution into that WSL instance:

    wsl --import-in-place RecoveredWSL 
    C:\WSL\instances\Recovered\ext4.vhdx
    

    Note that this wsl command requires the WSL version that is installed from the Microsoft Store (or via wsl --install on the latest Windows releases).

    Feel free to use a different name, of course. Once imported, you can access the distribution via:

    wsl ~ -d RecoveredWSL
    

    You can also set it as default, so it can simply be launched via wsl:

    wsl --set-default RecoveredWSL
    

If you really need to access the files from a "real" Ubuntu instance, it may be a bit more complicated, as you'll need to mount that vhdx file into Ubuntu. I haven't done that myself, but some see this answer on Ask Ubuntu for a possibility.

Important: If accessing the ext4.vhdx using this method, please make sure you are working from a secondary copy, as other questions on Ask Ubuntu indicate the possibility of corruption using these tools.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .