Index ¦ Archives ¦ Atom

How to mount a VHD file on linux

How to do it

Install libguestfs

For Debian and Ubuntu this is pretty easy

sudo apt-get install libguestfs-tools

For Red Hat, Centos, Fedora

sudo yum install libguestfs-tools

For Arch Linux (my distro of choice) you need to install 3 packages from the AUR

git clone https://aur.archlinux.org/hivex.git
git clone https://aur.archlinux.org/perl-sys-virt.git
git clone https://aur.archlinux.org/libguestfs.git

cd hivex
makepkg -si
cd ../perl-sys-virt
makepkg -si
cd ../libguestfs
makepkg -si

Once you have libguestfs as a normal user (not root / sudo) run guestmount

guestmount --add old_server_backup.vhd --ro /mnt/vhd/ -m /dev/sda1
  • --add option is for the image you want to access
  • --ro sets to read only, alternatively you could use --rw for read / write
  • /mnt/vhd the path where you want to mount the drive
  • -m /dev/sda1 specify which partition within the .vhd file you want to mount.

Enjoy :-)

My Rant

So I recently had to mount a backup of an old VM that was saved as a .vhd file and so I googled "How to mount a VHD on Linux" and the first result that came up was a Ubuntu forumns post where someone had asked the question and the top reply was someone else telling that person to go off and use a search engine. Followed by a link to Stack Overflow which didn't actually answer the question.

Some support forums and Stack Overflow in particular can be quite toxic to new comers (and even toxic to experienced veterans) and it's very infuriating when the top result on google is someone being told to just search google for the answer.

I know it can be annoying when simple questions come up over an over again but at the very least try to link to a useful article and if possible quote the relevant bit.

Anyway I hope my instructions saved someone the frustration that I went through.

Creative Commons License
Content on this site is licensed under a Creative Commons Attribution 4.0 International License.
Built using Pelican. Based on a theme by Giulio Fidente on github.