6

I had a nasty Windows 10 update problem locking myself out of my Windows installation. Unfortunately, I had no Windows backups.

I ended up loading into my dual-boot Ubuntu, making a backup of the whole Windows HDD with dc3dd, re-installing the Windows, and then restoring the dc3dd backup into a separate partition.

With that, I can now access all the old Windows files from the new Windows installation.

But I had some important projects within the WSL2 Ubuntu on the old Windows, which I would like to restore. Obviously, if I had wsl --export backups - this wouldn't be a problem, but I don't.

As far as I understand, it's not as simple as finding them somewhere deep in the old filesystem because they live in some sort of a virtual machine file.

So how can I approach this?

Thank you

Shkarik
  • 185

1 Answers1

7

It's fairly straightforward now for WSL2.

  1. First, you'll need to find the ext4.vhdx files from those distributions. If you installed the distribution from the Microsoft Store, then they will be under:

    <backed_up_drive>\Users\<username>\AppData\Local\Packages\<package_name>\LocalState\ext4.vhdx
    

    For Ubuntu distributions, the package name will start with "Canonical".

    Move the ext4.vhdx file to a location on the new system. I use something like:

    $ENV:userprofile\WSL\instances\Ubuntu_22.04_WSL2_Shkarik
    
  2. Next, make sure that you have the latest Windows 10 updates installed. You should then be able to install WSL itself from the Microsoft Store using this page. That's a later release release of WSL than comes with Windows 10, and it has the --import-in-place option.

  3. With the new WSL installed, open PowerShell (as a regular user, not Admin), navigate to the directory where you placed the ext4.vhdx and:

    # Import
    # wsl --import-in-place <new_distro_name> <path_to_vhdx>
    

    wsl --import-in-place Ubuntu_22.04_WSL2_Shkarik ./ext4.vhdx

    Optionally, set it as the default, if there are any others installed

    wsl --set-default Ubuntu_22.04_WSL2_Shkarik

    Start it with:

    wsl ~

    or

    wsl ~ -d Ubuntu_22.04_WSL2-Shkarik

  4. Once inside the distribution, you'll be the root user. You can set your default user per this answer.

Alternatively, you can just reinstall Ubuntu, then copy the old ext4.vhdx over the new one. However, I prefer being able to choose my own location and name for the distribution (per above). It also lets you quickly install another copy (for testing) with ubuntu.exe without interfering with your "day-to-day" files.

NotTheDr01ds
  • 28,025