From bf7e36a61b5209aa1dace648485cd70e1e93dfc8 Mon Sep 17 00:00:00 2001 From: Andrew Lukoshko Date: Thu, 12 Mar 2026 12:18:11 +0100 Subject: [PATCH] Fix BLS entries not corrected before grub2-mkconfig on RHEL 8 On RHEL 8-based distributions, grub2-mkconfig uses the grub.d/10_linux_bls script which reads Boot Loader Specification (BLS) entries from /boot/loader/entries/ and inlines them as menuentry blocks directly in grub.cfg. This is different from RHEL 9+ where grub.d/10_linux uses the `blscfg` command to load BLS entries at boot time. When kiwi builds a disk image, kernel packages are installed into a chroot (the image root). The BLS entries created by the kernel scriptlets at that point contain: - linux/initrd paths prefixed with the build host's image root path (e.g. /var/tmp/kiwi-build/build/image-root/boot/vmlinuz-...) - an options line from the build host's /proc/cmdline Previously, kiwi corrected these BLS entries only *after* running grub2-mkconfig. On RHEL 9+ this works fine because grub.cfg just contains `blscfg` and reads the (now corrected) BLS entries at boot time. On RHEL 8, however, grub2-mkconfig had already inlined the *uncorrected* BLS entries into grub.cfg, resulting in wrong kernel paths and boot options that caused the image to fail to boot. This commit adds calls to _fix_grub_loader_entries_boot_cmdline() and _fix_grub_loader_entries_linux_and_initrd_paths() before grub2-mkconfig, so that BLS entries are corrected before they get inlined into grub.cfg. The existing post-grub2-mkconfig calls are retained because grub2-mkconfig itself may re-create or modify BLS entries on some distributions. Fixes boot failure on AlmaLinux 8 ppc64le GenericCloud images built with kiwi where grub.cfg contained build-root paths like: linux /var/tmp/kiwi-build/build/image-root/boot/vmlinuz-4.18.0-... instead of: linux /vmlinuz-4.18.0-... --- kiwi/bootloader/config/grub2.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kiwi/bootloader/config/grub2.py b/kiwi/bootloader/config/grub2.py index 54cf8edb108..a173982fd12 100644 --- a/kiwi/bootloader/config/grub2.py +++ b/kiwi/bootloader/config/grub2.py @@ -289,6 +289,18 @@ def setup_disk_image_config( # Setup/Update loader environment self._setup_loader_variables() + # Fix BLS entries before running grub2-mkconfig. On distros + # like RHEL 8 the grub.d/10_linux_bls script reads BLS + # entries and inlines them as menuentry blocks in grub.cfg + # rather than emitting a blscfg command. BLS entries created + # during package installation in the kiwi image root often + # contain the build host path prefix in linux/initrd paths + # and the host's /proc/cmdline in the options field. Those + # must be corrected before grub2-mkconfig reads them, + # otherwise the wrong values are baked into grub.cfg. + self._fix_grub_loader_entries_boot_cmdline() + self._fix_grub_loader_entries_linux_and_initrd_paths() + # Disable os-prober, it takes information from the host it # runs on which is not necessarily matching with the image os.environ.update({'GRUB_DISABLE_OS_PROBER': 'true'})