I recently had a windows backup in vhd format stored on an EXT3 drive, only readable by my Ubuntu VM. Don't ask me how this happened, but I need to pull a few files off the backup.

Instead of copying the giant file to a Windows VM, I decided to mount the vhd image then ntfs partition in Ubuntu.

First build and install libvhdi and dependencies

sudo apt-get install -y autopoint libfuse-dev
# all my sources lives in ~/src
mkdir -p ~/src && cd ~/src
git clone [email protected]:libyal/libvhdi.git
cd libvhdi
sudo make install

Mount the image

sudo mkdir /mnt/vhdiimage
sudo vhdimount -X allow_root /media/mydrive/WindowsImageBackup/uuid.vhd /mnt/vhdiimage/

Figure out what type of disk image we're dealing with:

sudo su
cd /mnt/vhdiimage
fdisk -lu vhdi1

Find the offset of the partition you want to mount. Oh, look at that, what do you know? It's NTFS.

Disk vhdi1: 239.3 GB, 239286190080 bytes
16 heads, 48 sectors/track, 608536 cylinders, total 467355840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

 Device Boot      Start         End      Blocks   Id  System
vhdi1p1             128   467353727   233676800    7  HPFS/NTFS/exFAT

Calc the offset (Sector size * Start) and mount:

losetup -o $((128*512)) /dev/loop0 vhdi1
mkdir /mnt/backup
mount -o ro,noload /dev/loop0 /mnt/backup

The disk is now mounted in /mnt/backup