mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 05:26:58 +02:00
Merge pull request #263 from crawford/teeth
feat(teeth): Add new OEM and disk layout for teeth
This commit is contained in:
commit
17835eeb79
@ -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"
|
||||
|
@ -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
|
||||
@ -427,6 +437,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.
|
||||
|
||||
@ -445,18 +470,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):
|
||||
@ -486,8 +500,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
|
||||
@ -496,6 +511,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):
|
||||
@ -910,11 +931,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',
|
||||
|
@ -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
|
||||
@ -249,7 +255,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}")"
|
||||
|
Loading…
Reference in New Issue
Block a user