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.
This commit is contained in:
Michael Marineau 2013-07-08 15:42:24 -04:00
parent 711f7bd028
commit 21b9f711a4
2 changed files with 22 additions and 3 deletions

View File

@ -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'])

View File

@ -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"