From 44520881c7842c1dc0e8bc8b6e0a9c4100ad90eb Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Tue, 7 Oct 2014 16:52:50 -0700 Subject: [PATCH 1/2] build_image, image_to_vm: add disk-size assertions Assert that the image is a multiple of 1 MiB --- build_library/build_image_util.sh | 20 ++++++++++++++++++++ build_library/vm_image_util.sh | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index 25a59225bc..13bbbfd09f 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -163,6 +163,24 @@ package_provided() { done } +assert_image_size() { + local disk_img="$1" + local disk_type="$2" + + local size + size=$(qemu-img info -f "${disk_type}" --output json "${disk_img}" | \ + gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}' ; \ + exit ${PIPESTATUS[0]}) + if [[ $? -ne 0 ]]; then + die_notrace "assert failed: could not read image size" + fi + + MiB=$((1024*1024)) + if [[ $(($size % $MiB)) -ne 0 ]]; then + die_notrace "assert failed: image must be a multiple of 1 MiB ($size B)" + fi +} + start_image() { local image_name="$1" local disk_layout="$2" @@ -181,6 +199,8 @@ start_image() { "${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \ format "${disk_img}" + assert_image_size "${disk_img}" raw + "${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \ mount "${disk_img}" "${root_fs_dir}" trap "cleanup_mounts '${root_fs_dir}' && delete_prompt" EXIT diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index f52a28bd90..5aa2542801 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -331,6 +331,8 @@ setup_disk_image() { update "${VM_TMP_IMG}" fi + assert_image_size "${VM_TMP_IMG}" raw + info "Mounting image to $(relpath "${VM_TMP_ROOT}")" "${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \ mount "${VM_TMP_IMG}" "${VM_TMP_ROOT}" @@ -432,18 +434,22 @@ _write_raw_disk() { _write_qcow2_disk() { qemu-img convert -f raw "$1" -O qcow2 "$2" + assert_image_size "$2" qcow2 } _write_vhd_disk() { qemu-img convert -f raw "$1" -O vpc "$2" + assert_image_size "$2" vpc } _write_vmdk_ide_disk() { qemu-img convert -f raw "$1" -O vmdk -o adapter_type=ide "$2" + assert_image_size "$2" vmdk } _write_vmdk_scsi_disk() { qemu-img convert -f raw "$1" -O vmdk -o adapter_type=lsilogic "$2" + assert_image_size "$2" vmdk } _write_cpio_common() { From c226ac1c12b02c91ec8ac4cd577bddb9a54e1faf Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Mon, 29 Sep 2014 14:47:59 -0700 Subject: [PATCH 2/2] azure: finalize azure image Increase the root partition to ~28 GiB. --- build_library/disk_layout.json | 6 ++++++ build_library/vm_image_util.sh | 1 + 2 files changed, 7 insertions(+) diff --git a/build_library/disk_layout.json b/build_library/disk_layout.json index 77c8048bf4..ec59424785 100644 --- a/build_library/disk_layout.json +++ b/build_library/disk_layout.json @@ -76,6 +76,12 @@ "blocks":"12689408" } }, + "azure":{ + "9":{ + "label":"ROOT", + "blocks":"58752990" + } + }, "vagrant":{ "9":{ "label":"ROOT", diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 5aa2542801..8d3c96d40a 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -211,6 +211,7 @@ IMG_exoscale_OEM_PACKAGE=oem-exoscale ## azure IMG_azure_BOOT_KERNEL=0 IMG_azure_DISK_FORMAT=vhd +IMG_azure_DISK_LAYOUT=azure IMG_azure_OEM_PACKAGE=oem-azure ## hyper-v