Mount VHDx images in Linux

Gnu/Linux Sep 11, 2024

I needed some files from WSL and I am on Linux right now. Did I restart? nope! Instead, Geeked out and found that we can mount WSL images which are `.vhdx` files without much effort.

First, Install guestmount:

#Debian, Ubuntu, etc
>: sudo apt install libguestfs-tools

#Fedora, CentOs, etc
>: sudo dnf install libguestfs

Create a folder to mount and set user permission:

>: mkdir /mnt/wslImage
>: chown username:username /mnt/wslImage

Export this ENV to prevent permission errors:

>: export LIBGUESTFS_BACKEND=direct

Next, We need to find the path of the image. Mount C:\ partition from Windows in Linux and go to this folder:

/c/Users/USERNAME/AppData/Local/Packages/

Now search for a folder with your installed distribution name, I have Ubuntu installed, So:

CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc

This was the folder that Ububnu was in. Next, Open the folder and you can find vhdx file in LocalState folder under the Ubuntu folder.

Then run this command to mount:

>: guestmount --add file.vhdx --ro /mnt/wslImage -m /dev/sda

- file.vhdx: filename
- /dev/sda: the disk you wan't to mount it

If you had any issues, First open this link and search for the error, And if can't find anything, Search it on Bing, DuckDuckGo, Google, etc.

Enjoy!

Tags

Benyamin Eskandari

Curious, Experienced Android Developer Also in love with Rust, DevOps, and System Programming Trying to read a lot of books and learn a lot of things, I will write posts about my path on this journey.