Manipulate VHD (Virtual Hard Disk) images the open-source way.
C
Latest commit cafd9bf Mar 5, 2014 @andreiw vhdtool: fix build
Wanted me to list -luuid after object. Strange.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Permalink
Failed to load latest commit information.
test VHDtool: Add some Win7 test VHDs. Oct 15, 2011
Makefile vhdtool: fix build Mar 5, 2014
README Update README Oct 1, 2012
vhdtool.c Fix owerflow with dynamic disks >= 4G Aug 8, 2013

README

VHDtool
==========

A tool to examine and manipulate VHD images. Initially
meant as a way to test dynamic VHD support in my
Linux kernel loop VHD parser support. Images mount
in Win7.

Why would you use this instead of qemu-img? VHDtool
lets you tweak more parameters and create funky
VHDs (and will support differencing disks soon too!).

One more reason is that qemu-img actually produces
corrupt images that don't fit the VHD spec. Unsure
if they event mount on Win7.

Stay tuned.

Building
========

Builds on recent Linux (i.e. not RHEL5, *sigh*), and
needs libuuid (you probably have it, but look for
libuuid-devel or some similar package).

To build:

$ make

Examples
========

$ ./vhdtool 
./vhdtool [-s size] [-b block_size] [-c] [-t type] create|convert ...

$ ./vhdtool create
./vhdtool -s size [-b block_size] [-c] [-t type] create vhd-file-name
command 'create' failed

$ ./vhdtool convert
./vhdtool [-b block_size] [-c] [-t type] convert source-file-name dest-file-name
command 'convert' failed

Generate a 512-byte fixed VHD:

$ vhdtool -s 512 create test.vhd

Generate a 50 sector fixed VHD:

$ vhdtool -s 512s create test.vhd

Generate a 12mb dynamic VHD:

$ vhdtool -s 12m -t dyn create test.vhd

Generate a 12mb dynamic VHD with non-default (2mb) block size:

$ vhdtool -s 12m -b 4m create test.vhd

Convert a raw image to a VHD

$ vhdtool convert test.raw test.vhd

Valid size modifiers are:
b/B/*nothing* -> bytes
k/K           -> kilobytes
m/M           -> megabytes
g/G           -> gigabytes
t/T           -> terabytes
s/S           -> sectors

Special Considerations
======================

You need to pass the '-c' option if you are creating images < 127GiB
in size and the following apply to you:

1) You are converting a RAW disk imag and will be using it with the
   emulated IDE controller in Hyper-V.

2) You are creating a new VHD and are expecting to use it both with
   the emulated IDE controller and the virtual SCSI adapter in
   Hyper-V.

The '-c' option, will ensure that the disk size implied by C/H/S
calculations will never be less than the desired image size, with
the side effect of making the image a little larger.

Contact Info
============

Andrei Warkentin (andrey.warkentin@gmail.com, andreiw@vmware.com, andreiw@msalumni.com)