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
- Download the xen sources:
wget -q http://bits.xensource.com/oss-xen/release/4.2.0/xen-4.2.0.tar.gz
- Unpack the sources:
tar -xzf xen-4.2.0.tar.gz
- Go to tools:
cd xen-4.2.0/tools/
- Patch it:
wget https://github.com/citrix-openstack/xenserver-utils/raw/master/blktap2.patch -qO - | patch -p0
- Configure
./configure --disable-monitors --disable-ocamltools --disable-rombios --disable-seabios
- Make:
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
cd blktap2/vhd
export LD_LIBRARY_PATH=lib/
wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
qemu-img convert -O raw cirros-0.3.0-x86_64-disk.img cirros.raw
- 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
faketime '2010-01-01' ./vhd-util convert -s 1 -t 2 -i cirros.vhd -o 0.vhd