]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Handle older versions of kernel-install
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 14 Feb 2023 20:47:01 +0000 (21:47 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 14 Feb 2023 21:46:09 +0000 (22:46 +0100)
Older versions of kernel-install unconditionally write the initrd
to /boot/<machine-id>/<kver>. Let's detect that and move it to the
correct location.

mkosi/__init__.py

index 4939d70eb07492588a014c1586fa5ea6c581dc6e..12daa9af440dd15914b1957e1ec35cfc1c3cc773 100644 (file)
@@ -3077,6 +3077,14 @@ def run_kernel_install(state: MkosiState, cached: bool) -> None:
     if state.config.cache_initrd and cached:
         return
 
+    # CentOS Stream 8 has an old version of kernel-install that unconditionally writes initrds to
+    # /boot/<machine-id>/<kver>, so let's detect that and move them to the correct location.
+
+    if (p := state.root / "etc/machine-id").exists():
+        machine_id = p.read_text().strip()
+    else:
+        machine_id = None
+
     with complete_step("Generating initramfs images…"):
         for kver, kimg in gen_kernel_images(state):
             cmd: list[PathString] = ["kernel-install", "add", kver, Path("/") / kimg]
@@ -3086,6 +3094,12 @@ def run_kernel_install(state: MkosiState, cached: bool) -> None:
 
             run_workspace_command(state, cmd)
 
+            if machine_id and (p := state.root / "boot" / machine_id / kver / "initrd").exists():
+                shutil.move(p, state.root / state.installer.initrd_path(kver))
+
+    if machine_id and (p := state.root / "boot" / machine_id).exists():
+        shutil.rmtree(p)
+
 
 def run_preset_all(state: MkosiState) -> None:
     if state.for_cache or state.do_run_build_script: