From 7c4b500e92a372e240afab547cf4db86d27aa111 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 21 May 2021 11:11:01 -0400 Subject: [PATCH] Add boot.img function to CoreOS --- .../coreos/profiles/default/initprofile.sh | 4 +++- confluent_server/confluent/osimage.py | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/confluent_osdeploy/coreos/profiles/default/initprofile.sh b/confluent_osdeploy/coreos/profiles/default/initprofile.sh index accf9215..3064dd73 100644 --- a/confluent_osdeploy/coreos/profiles/default/initprofile.sh +++ b/confluent_osdeploy/coreos/profiles/default/initprofile.sh @@ -3,4 +3,6 @@ ln -s $1/images/pxeboot/vmlinuz $2/boot/kernel && \ ln -s $1/images/pxeboot/initrd.img $2/boot/initramfs/distribution && \ ln -s $1/images/ignition.img $2/boot/initramfs/ignition.img && \ mkdir -p $2/boot/efi/boot/ && \ -ln -s $1/images/pxeboot/rootfs.img $2/ +ln -s $1/images/pxeboot/rootfs.img $2/ && \ +mcopy -i $1/images/efiboot.img ::efi/redhat/grubx64.efi $2/boot/efi/boot/ && \ +mcopy -i $1/images/efiboot.img ::efi/boot/bootx64.efi $2/boot/efi/boot/ \ No newline at end of file diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index 2a99c33e..6db8820e 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -426,7 +426,19 @@ def _priv_check_oraclelinux(isoinfo): 'category': 'el{0}'.format(major)} -def check_rhcos(isoinfo): +def fixup_coreos(targpath): + # the efi boot image holds content that the init script would want + # to mcopy, but the boot sector is malformed usually, so change it to 1 + # sector per track + if os.path.exists(targpath + '/images/efiboot.img'): + with open(targpath + '/images/efiboot.img', 'rb+') as bootimg: + bootimg.seek(0x18) + if bootimg.read != b'\x00\x00': + bootimg.seek(0x18) + bootimg.write(b'\x01') + + +def check_coreos(isoinfo): arch = 'x86_64' # TODO: would check magic of vmlinuz to see which arch if 'zipl.prm' in isoinfo[1]: prodinfo = isoinfo[1]['zipl.prm'] @@ -522,7 +534,7 @@ def fingerprint(archive): if fun.startswith('check_'): name = globals()[fun](isoinfo) if name: - return name, isoinfo[0] + return name, isoinfo[0], fun.replace('check_', '') return None else: sum = hashlib.sha256(header) @@ -534,7 +546,7 @@ def fingerprint(archive): chunk = archive.read(32768) imginfo = HASHPRINTS.get(sum.hexdigest(), None) if imginfo: - return imginfo, None + return imginfo, None, None def import_image(filename, callback, backend=False, mfd=None): @@ -545,7 +557,7 @@ def import_image(filename, callback, backend=False, mfd=None): identity = fingerprint(archive) if not identity: return -1 - identity, imginfo = identity + identity, imginfo, funname = identity targpath = identity['name'] distpath = '/var/lib/confluent/distributions/' + targpath if identity.get('subname', None): @@ -586,6 +598,8 @@ def import_image(filename, callback, backend=False, mfd=None): del identity['subname'] with open(distpath + '/distinfo.yaml', 'w') as distinfo: distinfo.write(yaml.dump(identity, default_flow_style=False)) + if 'fixup_{0}'.format(funname) in globals(): + globals()['fixup_{0}'.format(funname)](targpath) callback({'progress': 1.0}) sys.stdout.write('\n') @@ -668,7 +682,7 @@ class MediaImporter(object): if not identity: raise exc.InvalidArgumentException('Unsupported Media') self.percent = 0.0 - identity, _ = identity + identity, _, _ = identity self.phase = 'copying' if not identity: raise Exception('Unrecognized OS Media')