From ed50f5fe0bca5215263f71f0897634898c03e6aa Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Thu, 29 May 2014 13:52:00 -0700 Subject: [PATCH 1/2] feat(disk_util): Replace Resize() with Update() The new Update() performs the same tasks as the old Resize() in addition to formatting previously-unformatted partitions. This allows children disk-layouts to repartition the base layout in addition to resizing. --- build_library/disk_util | 56 +++++++++++++++++++++++----------- build_library/vm_image_util.sh | 2 +- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/build_library/disk_util b/build_library/disk_util index 3c6001984c..b2d0a84910 100755 --- a/build_library/disk_util +++ b/build_library/disk_util @@ -229,6 +229,16 @@ def GetPartitionTableFromImage(options, config, partitions): else: part['image_compat'] = False + for part in partitions.itervalues(): + if not part.get('fs_type', None): + continue + with PartitionLoop(options, part) as loop_dev: + try: + part['image_fs_type'] = subprocess.check_output( + ['sudo', 'blkid', '-o', 'value', '-s', 'TYPE', loop_dev]).strip() + except subprocess.CalledProcessError: + part['image_fs_type'] = None + # Set compat flags for any partition not in the image for part in partitions.itervalues(): part.setdefault('image_exists', False) @@ -334,7 +344,7 @@ def BtrfsSubvolId(path): def FormatBtrfs(part, device): - """Format an ext2 or ext4 filesystem. + """Format a btrfs filesystem. Args: part: dict defining the partition @@ -432,6 +442,21 @@ def PartitionLoop(options, partition): Sudo(['losetup', '--detach', loop_dev]) +def FormatPartition(options, part): + print "Formatting partition %s (%s) as %s" % ( + part['num'], part['label'], part['fs_type']) + + with PartitionLoop(options, part) as loop_dev: + if part['fs_type'] in ('ext2', 'ext4'): + FormatExt(part, loop_dev) + elif part['fs_type'] == 'btrfs': + FormatBtrfs(part, loop_dev) + elif part['fs_type'] == 'vfat': + FormatFat(part, loop_dev) + else: + raise Exception("Unhandled fs type %s" % part['fs_type']) + + def Format(options): """Writes the given partition table and initialize fresh filesystems. @@ -450,18 +475,7 @@ def Format(options): if part['type'] == 'blank' or 'fs_type' not in part: continue - print "Formatting partition %s (%s) as %s" % ( - part['num'], part['label'], part['fs_type']) - - with PartitionLoop(options, part) as loop_dev: - if part['fs_type'] in ('ext2', 'ext4'): - FormatExt(part, loop_dev) - elif part['fs_type'] == 'btrfs': - FormatBtrfs(part, loop_dev) - elif part['fs_type'] == 'vfat': - FormatFat(part, loop_dev) - else: - raise Exception("Unhandled fs type %s" % part['fs_type']) + FormatPartition(options, part) def ResizeExt(part, device): @@ -491,8 +505,9 @@ def ResizeBtrfs(part, device): os.rmdir(btrfs_mount) -def Resize(options): - """Writes the given partition table and resize ext[234] filesystems. +def Update(options): + """Writes the given partition table, resize filesystems, and + format free partitions. Args: options: Flags passed to the script @@ -501,6 +516,12 @@ def Resize(options): config, partitions = LoadPartitionConfig(options) WritePartitionTable(options, config, partitions) + for part in partitions.itervalues(): + if not part.get('fs_type', None): + continue + elif not part['image_fs_type']: + FormatPartition(options, part) + for part in partitions.itervalues(): resize_func = None if not part.get('fs_type', None): @@ -915,11 +936,12 @@ def main(argv): a.add_argument('disk_image', help='path to disk image file') a.set_defaults(func=Format, create=True) - a = actions.add_parser('resize', help='write gpt and resize filesystems') + a = actions.add_parser('update', + help='write gpt, resize filesystems, and format free partitions') a.add_argument('--mbr_boot_code', default=DEFAULT_MBR_BOOT_CODE, help='path to mbr boot block, such as syslinux/gptmbr.bin') a.add_argument('disk_image', help='path to disk image file') - a.set_defaults(func=Resize, create=False) + a.set_defaults(func=Update, create=False) a = actions.add_parser('mount', help='mount filesystems in image') a.add_argument('--read_only', '-r', action='store_true', diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 795deabc0f..06e0d52f70 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -249,7 +249,7 @@ setup_disk_image() { if [[ $(_get_vm_opt PARTITIONED_IMG) -eq 1 ]]; then "${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \ - resize "${VM_TMP_IMG}" + update "${VM_TMP_IMG}" fi info "Mounting image to $(relpath "${VM_TMP_ROOT}")" From d9afc85b0ee41ccbb0613a820d1a32f7dd744014 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Thu, 29 May 2014 13:56:13 -0700 Subject: [PATCH 2/2] feat(teeth): Add new OEM and disk layout for teeth --- build_library/disk_layout.json | 13 ++++++++++--- build_library/vm_image_util.sh | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/build_library/disk_layout.json b/build_library/disk_layout.json index d10d60a638..444abb4b44 100644 --- a/build_library/disk_layout.json +++ b/build_library/disk_layout.json @@ -50,9 +50,9 @@ "mount":"/usr/share/oem" }, "7":{ - "type":"blank", - "label":"coreos-reserved", - "blocks":"0" + "label":"OEM-CONFIG", + "type":"coreos-reserved", + "blocks":"131072" }, "8":{ "type":"blank", @@ -80,6 +80,13 @@ "blocks":"33587200" } }, + "teeth":{ + "7":{ + "label":"config-2", + "type":"data", + "fs_type":"ext2" + } + }, "container":{ "1":{ "type":"blank" diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 06e0d52f70..1a63a39e2f 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -14,6 +14,7 @@ VALID_IMG_TYPES=( qemu_no_kexec rackspace rackspace_vhd + teeth vagrant vagrant_vmware_fusion virtualbox @@ -158,6 +159,11 @@ IMG_rackspace_vhd_BOOT_KERNEL=0 IMG_rackspace_vhd_DISK_FORMAT=vhd IMG_rackspace_vhd_OEM_PACKAGE=oem-rackspace +## teeth +IMG_teeth_DISK_FORMAT=qcow2 +IMG_teeth_DISK_LAYOUT=teeth +IMG_teeth_OEM_PACKAGE=oem-rackspace-teeth + ########################################################### # Validate and set the vm type to use for the rest of the functions