From 9734ac017fd05996d3b09505f62f3bdc5b166292 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 28 Aug 2013 11:30:47 -0700 Subject: [PATCH 1/3] feat(image_to_vm): Make disk layout configurable by VM type. Use the smaller base format for 'raw' disk images since these will usually be dd'd to a block device to create AMIs and what not. For images using qcow2 and vmdk stick with the larger vm size. --- build_library/vm_image_util.sh | 15 +++++++++++++-- image_to_vm.sh | 5 ++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 611f5ba6b1..2116e7a639 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -44,6 +44,9 @@ IMG_DEFAULT_OEM_PACKAGE= # May be raw, qcow2 (qemu), or vmdk (vmware, virtualbox) IMG_DEFAULT_DISK_FORMAT=raw +# Name of the partition layout from legacy_disk_layout.json +IMG_DEFAULT_DISK_LAYOUT=base + # Name of the target config format, default is no config IMG_DEFAULT_CONF_FORMAT= @@ -52,6 +55,7 @@ IMG_DEFAULT_MEM=1024 ## qemu IMG_qemu_DISK_FORMAT=qcow2 +IMG_qemu_DISK_LAYOUT=vm IMG_qemu_CONF_FORMAT=qemu ## xen @@ -61,24 +65,29 @@ IMG_xen_CONF_FORMAT=xl ## virtualbox IMG_virtualbox_DISK_FORMAT=vmdk +IMG_virtualbox_DISK_LAYOUT=vm IMG_virtualbox_CONF_FORMAT=ovf ## vagrant IMG_vagrant_DISK_FORMAT=vmdk +IMG_vagrant_DISK_LAYOUT=vm IMG_vagrant_CONF_FORMAT=vagrant IMG_vagrant_OEM_PACKAGE=oem-vagrant ## vagrant_vmware IMG_vagrant_vmware_fusion_DISK_FORMAT=vmdk +IMG_vagrant_vmware_fusion_DISK_LAYOUT=vm IMG_vagrant_vmware_fusion_CONF_FORMAT=vagrant_vmware_fusion IMG_vagrant_vmware_fusion_OEM_PACKAGE=oem-vagrant ## vmware IMG_vmware_DISK_FORMAT=vmdk +IMG_vmware_DISK_LAYOUT=vm IMG_vmware_CONF_FORMAT=vmx ## vmware_insecure IMG_vmware_insecure_DISK_FORMAT=vmdk +IMG_vmware_insecure_DISK_LAYOUT=vm IMG_vmware_insecure_CONF_FORMAT=vmware_zip IMG_vmware_insecure_OEM_PACKAGE=oem-vagrant @@ -88,6 +97,7 @@ IMG_ami_OEM_PACKAGE=oem-ami ## openstack, supports ec2's metadata format so use oem-ami IMG_openstack_DISK_FORMAT=qcow2 +IMG_openstack_DISK_LAYOUT=vm IMG_openstack_OEM_PACKAGE=oem-ami ## rackspace @@ -158,7 +168,7 @@ _disk_ext() { # alternate filesystem image for the state partition instead of the one # from VM_SRC_IMG. Start new image using the given disk layout. unpack_source_disk() { - local disk_layout="$1" + local disk_layout="${1:-$(_get_vm_opt DISK_LAYOUT)}" local alternate_state_image="$2" if [[ -n "${alternate_state_image}" && ! -f "${alternate_state_image}" ]] @@ -191,7 +201,8 @@ unpack_source_disk() { } resize_state_partition() { - local size_in_bytes="$1" + local disk_layout="${1:-$(_get_vm_opt DISK_LAYOUT)}" + local size_in_bytes=$(get_filesystem_size "${disk_layout}" ${NUM_STATEFUL}) local size_in_sectors=$(( size_in_bytes / 512 )) local size_in_mb=$(( size_in_bytes / 1024 / 1024 )) local original_size=$(stat -c%s "${TEMP_STATE}") diff --git a/image_to_vm.sh b/image_to_vm.sh index 2664257083..2e42ef1964 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -37,7 +37,7 @@ DEFINE_string format "qemu" \ "Output format, one of: ${VALID_IMG_TYPES[*]}" DEFINE_string from "" \ "Directory containing rootfs.image and mbr.image" -DEFINE_string disk_layout "vm" \ +DEFINE_string disk_layout "" \ "The disk layout type to use for this image." DEFINE_integer mem "${DEFAULT_MEM}" \ "Memory size for the vm config in MBs." @@ -111,9 +111,8 @@ trap vm_cleanup EXIT # Unpack image, using alternate state image if defined # Resize to use all available space in new disk layout -STATEFUL_SIZE=$(get_filesystem_size "${FLAGS_disk_layout}" ${NUM_STATEFUL}) unpack_source_disk "${FLAGS_disk_layout}" "${FLAGS_state_image}" -resize_state_partition "${STATEFUL_SIZE}" +resize_state_partition "${FLAGS_disk_layout}" # Optionally install any OEM packages install_oem_package From 8a488f890b3d8a2665bc44944729d7e8ebd2047d Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 28 Aug 2013 11:40:09 -0700 Subject: [PATCH 2/3] fix(image_to_vm): Increase STATE in vagrant images to 16GB Vagrant users are accustomed to much larger disk sizes so lets give it to them. I'm leaving the others as-is since it is easier to grow than shrink disks if anyone has a particular size they need. --- build_library/legacy_disk_layout.json | 8 ++++++++ build_library/vm_image_util.sh | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build_library/legacy_disk_layout.json b/build_library/legacy_disk_layout.json index 85c40f1d1c..098bf4b114 100644 --- a/build_library/legacy_disk_layout.json +++ b/build_library/legacy_disk_layout.json @@ -73,6 +73,14 @@ "type":"data", "blocks":"6291456" } + ], + "vagrant": [ + { + "num": 9, + "label":"STATE", + "type":"data", + "blocks":"33587200" + } ] } } diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 2116e7a639..205cb50377 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -70,13 +70,13 @@ IMG_virtualbox_CONF_FORMAT=ovf ## vagrant IMG_vagrant_DISK_FORMAT=vmdk -IMG_vagrant_DISK_LAYOUT=vm +IMG_vagrant_DISK_LAYOUT=vagrant IMG_vagrant_CONF_FORMAT=vagrant IMG_vagrant_OEM_PACKAGE=oem-vagrant ## vagrant_vmware IMG_vagrant_vmware_fusion_DISK_FORMAT=vmdk -IMG_vagrant_vmware_fusion_DISK_LAYOUT=vm +IMG_vagrant_vmware_fusion_DISK_LAYOUT=vagrant IMG_vagrant_vmware_fusion_CONF_FORMAT=vagrant_vmware_fusion IMG_vagrant_vmware_fusion_OEM_PACKAGE=oem-vagrant From dfb7d8d115e5c15c790dce02fa535e7ea2c0f1fe Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 28 Aug 2013 11:48:18 -0700 Subject: [PATCH 3/3] fix(build_library): Drop default 'base' layout to 512MB for STATE. This will further reduce the amount of dd'ing required when using block devices. --- build_library/legacy_disk_layout.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_library/legacy_disk_layout.json b/build_library/legacy_disk_layout.json index 098bf4b114..fcdcf0ec0c 100644 --- a/build_library/legacy_disk_layout.json +++ b/build_library/legacy_disk_layout.json @@ -63,7 +63,7 @@ "num": 9, "label":"STATE", "type":"data", - "blocks":"2097152" + "blocks":"1048576" } ], "vm": [