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.

Patch and build vhd-util

  1. Download the xen sources:
    wget -q http://bits.xensource.com/oss-xen/release/4.2.0/xen-4.2.0.tar.gz
  2. Unpack the sources:
    tar -xzf xen-4.2.0.tar.gz
  3. Go to tools:
    cd xen-4.2.0/tools/
  4. Patch it:
    wget https://github.com/citrix-openstack/xenserver-utils/raw/master/blktap2.patch -qO - | patch -p0
  5. Configure
    ./configure --disable-monitors --disable-ocamltools --disable-rombios --disable-seabios
  6. Make:

Create a vhd image

I will use a qcow2 image, convert it to raw with qemu-img, and use vhd-util to convert it to vhd

  1. cd blktap2/vhd
  2. export LD_LIBRARY_PATH=lib/
  3. wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
  4. qemu-img convert -O raw cirros-0.3.0-x86_64-disk.img cirros.raw
  5. 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:
    faketime '2010-01-01' ./vhd-util convert -s 0 -t 1 -i cirros.raw -o cirros.vhd
  6. faketime '2010-01-01' ./vhd-util convert -s 1 -t 2 -i cirros.vhd -o 0.vhd