]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Centralize vmlinuz fixup logic
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 13 Apr 2024 14:40:45 +0000 (16:40 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 14 Apr 2024 13:47:28 +0000 (15:47 +0200)
Let's run this logic for all distributions, and also run it after
running postinst scripts, to deal with kernel packages that are
installed in a postinst script.

mkosi/__init__.py
mkosi/distributions/debian.py
mkosi/distributions/mageia.py
mkosi/distributions/openmandriva.py

index b41e1f1ae1e0e1e2384bd2d981c3ccf45b1f8e7b..45c347add185a701b35f30e395aaf00edb368783 100644 (file)
@@ -1616,6 +1616,18 @@ def gzip_binary(context: Context) -> str:
     return "pigz" if find_binary("pigz", root=context.config.tools()) else "gzip"
 
 
+def fixup_vmlinuz_location(context: Context) -> None:
+    for d in context.root.glob("boot/vmlinuz-*"):
+        kver = d.name.removeprefix("vmlinuz-")
+        vmlinuz = context.root / "usr/lib/modules" / kver / "vmlinuz"
+        # Some distributions (OpenMandriva) symlink /usr/lib/modules/<kver>/vmlinuz to /boot/vmlinuz-<kver>, so get rid
+        # of the symlink and copy the actual vmlinuz to /usr/lib/modules/<kver>.
+        if vmlinuz.is_symlink() and vmlinuz.is_relative_to("/boot"):
+            vmlinuz.unlink()
+        if not vmlinuz.exists():
+            shutil.copy2(d, vmlinuz)
+
+
 def gen_kernel_images(context: Context) -> Iterator[tuple[str, Path]]:
     if not (context.root / "usr/lib/modules").exists():
         return
@@ -3564,6 +3576,7 @@ def build_image(context: Context) -> None:
                 run_prepare_scripts(context, build=False)
                 install_build_packages(context)
                 run_prepare_scripts(context, build=True)
+                fixup_vmlinuz_location(context)
                 run_depmod(context, cache=True)
 
             save_cache(context)
@@ -3581,6 +3594,7 @@ def build_image(context: Context) -> None:
         install_build_dest(context)
         install_extra_trees(context)
         run_postinst_scripts(context)
+        fixup_vmlinuz_location(context)
 
         configure_autologin(context)
         configure_os_release(context)
index fddbb629dbebc310cbfe5ed3400045a7b0fbda73..696b16d44207e3bfe827cb2b8d3867f2dad2ce80 100644 (file)
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
-import shutil
 import tempfile
 from collections.abc import Iterable, Sequence
 from pathlib import Path
@@ -205,12 +204,6 @@ class Installer(DistributionInstaller):
 
         policyrcd.unlink()
 
-        for d in context.root.glob("boot/vmlinuz-*"):
-            kver = d.name.removeprefix("vmlinuz-")
-            vmlinuz = context.root / "usr/lib/modules" / kver / "vmlinuz"
-            if not vmlinuz.exists():
-                shutil.copy2(d, vmlinuz)
-
         # systemd-gpt-auto-generator is disabled by default in Ubuntu:
         # https://git.launchpad.net/ubuntu/+source/systemd/tree/debian/systemd.links?h=ubuntu/noble-proposed.
         # Let's make sure it is enabled by default in our images.
index 0fe44e88977ebb0b867e90df35e2ffb0143dea6f..117964b21537d920de04c637b4ee24d7fc62f633 100644 (file)
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
-import shutil
 from collections.abc import Iterable, Sequence
 
 from mkosi.config import Architecture
@@ -32,12 +31,6 @@ class Installer(fedora.Installer):
     def install_packages(cls, context: Context, packages: Sequence[str], apivfs: bool = True) -> None:
         super().install_packages(context, packages, apivfs)
 
-        for d in context.root.glob("boot/vmlinuz-*"):
-            kver = d.name.removeprefix("vmlinuz-")
-            vmlinuz = context.root / "usr/lib/modules" / kver / "vmlinuz"
-            if not vmlinuz.exists():
-                shutil.copy2(d, vmlinuz)
-
     @classmethod
     @listify
     def repositories(cls, context: Context) -> Iterable[RpmRepository]:
index d6dc031e50f32f72ad2c5369d5d77ff80bd28451..5e62353d5a962fb398a5ebc227c469e8af6255d6 100644 (file)
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
-import shutil
 from collections.abc import Iterable, Sequence
 
 from mkosi.config import Architecture
@@ -32,16 +31,6 @@ class Installer(fedora.Installer):
     def install_packages(cls, context: Context, packages: Sequence[str], apivfs: bool = True) -> None:
         super().install_packages(context, packages, apivfs)
 
-        for d in context.root.glob("boot/vmlinuz-*"):
-            kver = d.name.removeprefix("vmlinuz-")
-            vmlinuz = context.root / "usr/lib/modules" / kver / "vmlinuz"
-            # Openmandriva symlinks /usr/lib/modules/<kver>/vmlinuz to /boot/vmlinuz-<kver>, so get rid of the symlink
-            # and put the actual vmlinuz in /usr/lib/modules/<kver>.
-            if vmlinuz.is_symlink():
-                vmlinuz.unlink()
-            if not vmlinuz.exists():
-                shutil.copy2(d, vmlinuz)
-
     @classmethod
     @listify
     def repositories(cls, context: Context) -> Iterable[RpmRepository]: