From 21b9f711a44b4c9ff5c751e8b0c1122e25f84143 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Mon, 8 Jul 2013 15:42:24 -0400 Subject: [PATCH 1/2] feat(cgpt): Statically allocate UUIDs for ROOT partitions. Before we can switch from using device names in root= to partition table UUIDs we need some values that will remain consistent across upgrades since the partition table is not updated when filesystems are. --- build_library/cgpt.py | 16 +++++++++++++--- build_library/legacy_disk_layout.json | 9 +++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/build_library/cgpt.py b/build_library/cgpt.py index cd0d89c418..57ad46b247 100755 --- a/build_library/cgpt.py +++ b/build_library/cgpt.py @@ -8,6 +8,7 @@ import json import os import re import sys +import uuid from optparse import OptionParser # First sector we can use. @@ -35,7 +36,7 @@ def LoadPartitionConfig(filename): valid_keys = set(('_comment', 'metadata', 'layouts')) valid_layout_keys = set(( '_comment', 'type', 'num', 'label', 'blocks', 'block_size', 'fs_blocks', - 'fs_block_size', 'features')) + 'fs_block_size', 'features', 'uuid')) if not os.path.exists(filename): raise ConfigNotFound('Partition config %s was not found!' % filename) @@ -77,6 +78,15 @@ def LoadPartitionConfig(filename): raise InvalidLayout( 'Filesystem may not be larger than partition: %s %s: %d > %d' % (layout_name, part['label'], part['fs_bytes'], part['bytes'])) + + if 'uuid' in part: + try: + # double check the string formatting + part['uuid'] = str(uuid.UUID(part['uuid'])) + except ValueError as e: + raise InvalidLayout('Invalid uuid %r: %s' % (part['uuid'], e)) + else: + part['uuid'] = str(uuid.uuid4()) except KeyError as e: raise InvalidLayout('Layout is missing required entries: %s' % e) @@ -291,9 +301,9 @@ def WriteLayoutFunction(options, sfile, func_name, image_type, config): # Pass 2: Write out all the cgpt add commands. for partition in partitions: if partition['type'] != 'blank': - sfile.write('$GPT add -i %d -b $CURR -s %s -t %s -l %s $1 && ' % ( + sfile.write('$GPT add -i %d -b $CURR -s %s -t %s -l %s -u %s $1 && ' % ( partition['num'], str(partition['var']), partition['type'], - partition['label'])) + partition['label'], partition['uuid'])) if partition['type'] == 'efi': sfile.write('$GPT boot -p -b $2 -i %d $1\n' % partition['num']) diff --git a/build_library/legacy_disk_layout.json b/build_library/legacy_disk_layout.json index 6ca9d47c69..724c93895d 100644 --- a/build_library/legacy_disk_layout.json +++ b/build_library/legacy_disk_layout.json @@ -21,6 +21,7 @@ { "num": 3, "label":"ROOT-A", + "uuid":"7130c94a-213a-4e5a-8e26-6cce9662f132", "type":"coreos-rootfs", "blocks":"4194304", "fs_blocks":"262144" @@ -28,6 +29,7 @@ { "num": 4, "label":"ROOT-B", + "uuid":"e03dd35c-7c2d-4a47-b3fe-27f15780a57c", "type":"coreos-rootfs", "blocks":"4194304", "fs_blocks":"262144" @@ -35,6 +37,7 @@ { "num": 5, "label":"ROOT-C", + "uuid":"d82521b4-07ac-4f1c-8840-ddefedc332f3", "type":"coreos-rootfs", "blocks":"1" }, @@ -68,6 +71,7 @@ { "num": 3, "label":"ROOT-A", + "uuid":"7130c94a-213a-4e5a-8e26-6cce9662f132", "type":"coreos-rootfs", "blocks":"2539520", "fs_blocks":"262144" @@ -75,6 +79,7 @@ { "num": 4, "label":"ROOT-B", + "uuid":"e03dd35c-7c2d-4a47-b3fe-27f15780a57c", "type":"coreos-rootfs", "blocks":"1" } @@ -89,6 +94,7 @@ { "num": 3, "label":"ROOT-A", + "uuid":"7130c94a-213a-4e5a-8e26-6cce9662f132", "type":"coreos-rootfs", "blocks":"860160", "fs_blocks":"102400" @@ -96,6 +102,7 @@ { "num": 4, "label":"ROOT-B", + "uuid":"e03dd35c-7c2d-4a47-b3fe-27f15780a57c", "type":"coreos-rootfs", "blocks":"1" }, @@ -110,6 +117,7 @@ { "num": 3, "label":"ROOT-A", + "uuid":"7130c94a-213a-4e5a-8e26-6cce9662f132", "type":"coreos-rootfs", "blocks":"2097152", "fs_blocks":"262144" @@ -117,6 +125,7 @@ { "num": 4, "label":"ROOT-B", + "uuid":"e03dd35c-7c2d-4a47-b3fe-27f15780a57c", "type":"coreos-rootfs", "blocks":"2097152", "fs_blocks":"262144" From 3fa29024e102fc0d3ae77a3224cde41008beaa41 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Mon, 8 Jul 2013 16:28:12 -0400 Subject: [PATCH 2/2] fix(build_image): Configure legacy bootloaders to set root by UUID. Make use of the new partition UUIDs for ROOT-A and ROOT-B in the root= kernel parameters provided by the legacy (non-kexec) bootloaders. This makes all of our images bootable as-is without having to pass them through image_to_vm.sh. :-D --- build_library/cgpt.py | 24 +++++++++++++ .../create_legacy_bootloader_templates.sh | 17 +++++---- build_library/disk_layout_util.sh | 8 +++++ image_to_vm.sh | 35 ------------------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/build_library/cgpt.py b/build_library/cgpt.py index 57ad46b247..b2980cded9 100755 --- a/build_library/cgpt.py +++ b/build_library/cgpt.py @@ -485,6 +485,26 @@ def GetNum(options, image_type, layout_filename, label): return '-1' +def GetUuid(options, image_type, layout_filename, label): + """Returns the unique partition UUID for a given label. + + Note: Only useful if the UUID is specified in the config file, otherwise + the value returned unlikely to be what is actually used in the image. + + Args: + options: Flags passed to the script + image_type: Type of image eg base/test/dev/prod + layout_filename: Path to partition configuration file + label: Label of the partition you want to read from + Returns: + String containing the requested UUID + """ + + partitions = GetPartitionTableFromConfig(options, layout_filename, image_type) + partition = GetPartitionByLabel(partitions, label) + return partition['uuid'] + + def DoDebugOutput(options, image_type, layout_filename): """Prints out a human readable disk layout in on-disk order. @@ -557,6 +577,10 @@ def main(argv): 'usage': ['', '', '