Convert a raw image to XenServer – VHD

If your choice of hypervisor is XenServer, and using ext storage, the virtual disks are stored in vhd format. I would like to show how to convert a raw image to VHD format.

The first option could be to use the qemu-img tool, specifying vpc format. This solution works, until you decide to snapshot that virtual disk. OpenStack itself is creating snapshots of downloaded images, so I definitely needed that feature. The route is to compile the blktap2 utilities, and patch them. This patch is floating around the web, and needed some adjustments to work with the 4.2 version of xen.

As a timestamp is stored inside the vhd file, and it is checked by the OpenStack xapi plugin, I need to rewind the time, to avoid “primary footer invalid: creation time in future” errors, that come from vhd-util check -n vhdfile, so using faketime: