From 7b6cf246d62acb380659dde07c56f7072fd01795 Mon Sep 17 00:00:00 2001
From: Gregory Haynes <greg@greghaynes.net>
Date: Mon, 16 Feb 2015 17:20:01 -0800
Subject: [PATCH] Support VHD output format
This useful for building images for xen.
Change-Id: Ib716bd7fc1ed979968ea92f46f1644038e40df66
---
bin/disk-image-create | 27 +++++++++++++++++++++++++--
lib/img-functions | 7 +++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/bin/disk-image-create b/bin/disk-image-create
index ecc3f49..c96edec 100755
--- a/bin/disk-image-create
+++ b/bin/disk-image-create
@@ -45,8 +45,9 @@ function show_options () {
echo "Options:"
echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)"
echo " -o imagename -- set the imagename of the output image file(default image)"
- echo " -t qcow2,tar,raw -- set the image types of the output image files (default qcow2)"
- echo " File types should be comma separated"
+ echo " -t qcow2,tar,vhd,raw -- set the image types of the output image files (default qcow2)"
+ echo " File types should be comma separated. VHD outputting requires the vhd-util"
+ echo " executable be in your PATH."
echo " -x -- turn on tracing"
echo " -u -- uncompressed; do not compress the image - larger but faster"
echo " -c -- clear environment before starting work"
@@ -80,6 +81,10 @@ function show_options () {
echo
echo "NOTE: At least one distribution root element must be specified."
echo
+ echo "NOTE: If using the VHD output format you need to have a patched version of vhd-util installed for the image"
+ echo " to be bootable. The patch is available here: https://github.com/emonty/vhd-util/blob/master/debian/patches/citrix"
+ echo " and a PPA with the patched tool is available here: https://launchpad.net/~openstack-ci-core/+archive/ubuntu/vhd-util"
+ echo
echo "Examples:"
if [ "$IS_RAMDISK" == "0" ]; then
echo " ${SCRIPTNAME} -a amd64 -o ubuntu-amd64 vm ubuntu"
@@ -159,6 +164,24 @@ if [ "${#IMAGE_TYPES[@]}" = "1" ]; then
export IMAGE_NAME=${IMAGE_NAME%%\.${IMAGE_TYPES[0]}}
fi
+# Check for required tools early on
+for X in ${!IMAGE_TYPES[@]}; do
+ case "${IMAGE_TYPES[$X]}" in
+ qcow2)
+ if [ -z "$(which qemu-img)" ]; then
+ echo "qcow2 output format specified but qemu-img executable not found."
+ exit 1
+ fi
+ ;;
+ vhd)
+ if [ -z "$(which vhd-util)" ]; then
+ echo "vhd output format specified but no vhd-util executable found."
+ exit 1
+ fi
+ ;;
+ esac
+done
+
# NOTE: Tuning the rootfs uuid works only for ext filesystems.
# Rely on the below environment variable only for ext filesystems.
export DIB_IMAGE_ROOT_FS_UUID=$(uuidgen -r)
diff --git a/lib/img-functions b/lib/img-functions
index 852f575..0f3b82c 100644
--- a/lib/img-functions
+++ b/lib/img-functions
@@ -120,6 +120,13 @@ function compress_and_save_image () {
fi
if [ "$IMAGE_TYPE" = "raw" ]; then
mv $TMP_IMAGE_PATH $1-new
+ elif [ "$IMAGE_TYPE" == "vhd" ]; then
+ cp $TMP_IMAGE_PATH $1-intermediate
+ vhd-util convert -s 0 -t 1 -i $1-intermediate -o $1-intermediate
+ vhd-util convert -s 1 -t 2 -i $1-intermediate -o $1-new
+ # The previous command creates a .bak file
+ rm $1-intermediate.bak
+ OUT_IMAGE_PATH=$1-new
else
echo "Converting image using qemu-img convert"
qemu-img convert ${COMPRESS_IMAGE:+-c} -f raw $TMP_IMAGE_PATH -O $IMAGE_TYPE $EXTRA_OPTIONS $1-new