Support VHD output format
This useful for building images for xen. Change-Id: Ib716bd7fc1ed979968ea92f46f1644038e40df66
This commit is contained in:
		 Gregory Haynes
					Gregory Haynes
				
			
				
					committed by
					
						 Monty Taylor
						Monty Taylor
					
				
			
			
				
	
			
			
			 Monty Taylor
						Monty Taylor
					
				
			
						parent
						
							65ad6377a6
						
					
				
				
					commit
					7937fb5392
				
			| @@ -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" | ||||
| @@ -78,6 +79,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" | ||||
| @@ -155,6 +160,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) | ||||
|   | ||||
| @@ -117,6 +117,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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user