From 305a54f1a2019e3be305bc67ce06ab1af9807c44 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 12 Mar 2025 12:23:15 +0100 Subject: [PATCH] stages/rpm: add new kernel_install_env options Add support for setting environment variables for kernel-install and its plugins. These can be used to control the behaviour of kernel-install during the kernel rpm installation. Currently, we only add support for $BOOT_ROOT, which we need to control the path where the kernel should be installed. Normally, kernel-install scripts will detect the correct path based on the filesystem layout, specifically the ESP path. However, during our installation the filesystem is not yet set up, so with this option, we can control the installation path based on the location we know the ESP will be mounted in the final image. This is a very similar override to what we do with the org.osbuild.fix-bls stage. The stage option is added under a kernel_install_env object so we can potentially support more of the known env vars in the future. --- stages/org.osbuild.rpm | 10 +++++++++- stages/org.osbuild.rpm.meta.json | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/stages/org.osbuild.rpm b/stages/org.osbuild.rpm index a667245c..b22b59e0 100755 --- a/stages/org.osbuild.rpm +++ b/stages/org.osbuild.rpm @@ -202,6 +202,14 @@ def main(tree, inputs, options): "--define", macro, ] + env = os.environ.copy() + # update the environment with variables for kernel-install if any are defined + kernel_install_env = options.get("kernel_install_env", {}) + if kernel_install_env: + boot_root = kernel_install_env.get("boot_root") + if boot_root: + env["BOOT_ROOT"] = boot_root + with tempfile.NamedTemporaryFile(prefix="manifest.", mode='w') as manifest: manifest.writelines(c + '\n' for c in packages) manifest.flush() @@ -216,7 +224,7 @@ def main(tree, inputs, options): # reading. "--nosignature", "--install", manifest.name - ], cwd=pkgpath, check=True) + ], cwd=pkgpath, check=True, env=env) for key in options.get("gpgkeys.fromtree", []): path = os.path.join(tree, key.lstrip("/")) diff --git a/stages/org.osbuild.rpm.meta.json b/stages/org.osbuild.rpm.meta.json index 971c0c0f..a5051b02 100644 --- a/stages/org.osbuild.rpm.meta.json +++ b/stages/org.osbuild.rpm.meta.json @@ -146,6 +146,18 @@ "ostree_booted": { "type": "boolean", "description": "Create the '/run/ostree-booted' marker" + }, + "kernel_install_env": { + "description": "Set environment variables understood by kernel-install and plugins (kernel-install(8))", + "type": "object", + "additionalProperties": false, + "properties": { + "boot_root": { + "type": "string", + "pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$", + "description": "Sets $BOOT_ROOT for kernel-install to override $KERNEL_INSTALL_BOOT_ROOT, the installation location for boot entries" + } + } } } },