|
| 1 | +From 55a25d1428a35f713fce62f68db35243d64ed564 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jonathan Lebon < [email protected]> |
| 3 | +Date: Wed, 20 Aug 2025 12:14:44 -0400 |
| 4 | +Subject: [PATCH] stages/coreos.live-artifacts: rework volume ID handling |
| 5 | + |
| 6 | +In https://github.com/osbuild/osbuild/pull/2148, we changed the logic to |
| 7 | +generate the volume ID from the data in `/usr/lib/os-release` to sever |
| 8 | +the reliance on metadata in the embedded treefile that will no longer |
| 9 | +exist. |
| 10 | + |
| 11 | +This had no effect in FCOS, but had an effect in RHCOS, which |
| 12 | +went from a volume ID of `rhcos-...` to `rhel-coreos-...`. |
| 13 | +This was considered harmless at the time, but in fact ended |
| 14 | +up affecting the OpenShift Assisted Image Service. See e.g. |
| 15 | +https://github.com/openshift/assisted-image-service/pull/477 which |
| 16 | +attempted to adapt that code. But in the end, it felt safer and less |
| 17 | +work to just revert back to the previous volume ID. So here we are. |
| 18 | + |
| 19 | +But we still don't want to go back to using the embedded treefile. |
| 20 | +Instead, we now have access to the OS name to use as a label on the |
| 21 | +container image. This label gets serialized into the aleph during the |
| 22 | +creation of the metal image (via the `org.osbuild.ostree.aleph` stage) |
| 23 | +which we have access here when mounting the metal image via loopback. |
| 24 | + |
| 25 | +So pick it up from there and use that. But in case it's missing, |
| 26 | +fallback to the previous logic rather than hard fail to make this easier |
| 27 | +to ratchet in. |
| 28 | +--- |
| 29 | + stages/org.osbuild.coreos.live-artifacts.mono | 27 +++++++++++-------- |
| 30 | + 1 file changed, 16 insertions(+), 11 deletions(-) |
| 31 | + |
| 32 | +diff --git a/stages/org.osbuild.coreos.live-artifacts.mono b/stages/org.osbuild.coreos.live-artifacts.mono |
| 33 | +index 4a95b607..8c1ce2ad 100755 |
| 34 | +--- a/stages/org.osbuild.coreos.live-artifacts.mono |
| 35 | ++++ b/stages/org.osbuild.coreos.live-artifacts.mono |
| 36 | +@@ -130,11 +130,6 @@ def make_stream_hash(src, dest): |
| 37 | + outf.write(hashlib.sha256(buf).hexdigest() + '\n') |
| 38 | + |
| 39 | + |
| 40 | +-def get_os_name(tree): |
| 41 | +- os_release = osrelease.parse_files(os.path.join(tree, 'usr', 'lib', 'os-release')) |
| 42 | +- return f"{os_release['ID']}-{os_release['VARIANT_ID']}" |
| 43 | +- |
| 44 | +- |
| 45 | + def ensure_glob(pathname, n="", **kwargs): |
| 46 | + """ |
| 47 | + Call glob.glob() and fail if there are no results or |
| 48 | +@@ -300,7 +295,7 @@ def genisoargs_s390x(paths, test_fixture, volid, name_version): |
| 49 | + os.path.join(os.path.relpath(paths["iso/images"], paths["iso"]), 'cdboot.img')] |
| 50 | + |
| 51 | + |
| 52 | +-def gen_live_artifacts(paths, tree, filenames, deployed_tree, loop_client, version, blsentry_kargs): |
| 53 | ++def gen_live_artifacts(paths, tree, filenames, deployed_tree, loop_client, version, blsentry_kargs, osname): |
| 54 | + """ |
| 55 | + Generate the ISO image. |
| 56 | + Based on the Lorax templates [1]. |
| 57 | +@@ -310,7 +305,7 @@ def gen_live_artifacts(paths, tree, filenames, deployed_tree, loop_client, versi |
| 58 | + [2] https://fedoraproject.org/wiki/User:Pjones/BootableCDsForBIOSAndUEFI |
| 59 | + """ |
| 60 | + |
| 61 | +- base_name = get_os_name(tree=deployed_tree) |
| 62 | ++ base_name = osname |
| 63 | + name_version = f'{base_name}-{version}' |
| 64 | + # The short volume ID can only be 32 characters (bytes probably). We may in |
| 65 | + # the future want to shorten this more intelligently, otherwise we truncate the |
| 66 | +@@ -555,7 +550,7 @@ def mkrootfs_metal(paths, workdir, img_metal, fstype, fsoptions, loop_client): |
| 67 | + Mounts a copy of the metal image and modifies it accordingly to create a (fstype) rootfs from its contents for the |
| 68 | + live ISO. fstype must be squashfs or erofs. |
| 69 | + |
| 70 | +- Returns the bls entry kernel arguments for the ISO bootloader. |
| 71 | ++ Returns the bls entry kernel arguments for the ISO bootloader and the OS name extracted from the aleph. |
| 72 | + """ |
| 73 | + basearch = os.uname().machine |
| 74 | + tmp_rootfs_dir = os.path.join(workdir, 'tmp-rootfs-dir') |
| 75 | +@@ -637,7 +632,15 @@ def mkrootfs_metal(paths, workdir, img_metal, fstype, fsoptions, loop_client): |
| 76 | + if len(blsentry_kargs) == 0: |
| 77 | + raise ValueError("found no kargs in metal image") |
| 78 | + |
| 79 | +- return blsentry_kargs |
| 80 | ++ # while we're here, also get the OS name from the aleph since we'll |
| 81 | ++ # need that for the volume ID |
| 82 | ++ ALEPH_FILENAME = ".aleph-version.json" |
| 83 | ++ with open(os.path.join(tmp_rootfs_dir, ALEPH_FILENAME), encoding='utf8') as f: |
| 84 | ++ aleph = json.load(f) |
| 85 | ++ |
| 86 | ++ osname = aleph.get('container-image', {}).get('image-labels', {}).get('com.coreos.osname') |
| 87 | ++ |
| 88 | ++ return (blsentry_kargs, osname) |
| 89 | + |
| 90 | + |
| 91 | + # pylint: disable=too-many-branches |
| 92 | +@@ -923,7 +926,9 @@ def main(workdir, tree, inputs, options, loop_client): |
| 93 | + |
| 94 | + mk_osmet_files(deployed_tree, img_metal, img_metal4k, loop_client, paths, os_release) |
| 95 | + |
| 96 | +- blsentry_kargs = mkrootfs_metal(paths, workdir, img_metal, fstype, fsoptions, loop_client) |
| 97 | ++ (blsentry_kargs, osname) = mkrootfs_metal(paths, workdir, img_metal, fstype, fsoptions, loop_client) |
| 98 | ++ if not osname: |
| 99 | ++ osname = f"{os_release['ID']}-{os_release['VARIANT_ID']}" |
| 100 | + |
| 101 | + # Generate rootfs image |
| 102 | + # The rootfs must be uncompressed because the ISO mounts root.squashfs |
| 103 | +@@ -951,7 +956,7 @@ def main(workdir, tree, inputs, options, loop_client): |
| 104 | + extend_initramfs(initramfs=paths["iso/images/pxeboot/initrd.img"], tree=paths["initrd"]) |
| 105 | + |
| 106 | + filenames = options['filenames'] |
| 107 | +- gen_live_artifacts(paths, tree, filenames, deployed_tree, loop_client, version, blsentry_kargs) |
| 108 | ++ gen_live_artifacts(paths, tree, filenames, deployed_tree, loop_client, version, blsentry_kargs, osname) |
| 109 | + |
| 110 | + |
| 111 | + if __name__ == "__main__": |
| 112 | +-- |
| 113 | +2.50.1 |
| 114 | + |
0 commit comments