x86: fix bios mkimage during efi image generation
authorAlif M. Ahmad <alive4ever@live.com>
Sun, 4 Mar 2018 01:40:21 +0000 (01:40 +0000)
committerJo-Philipp Wich <jo@mein.io>
Wed, 14 Aug 2019 06:09:27 +0000 (08:09 +0200)
Previously, grub-mkimage embeds full-featured grub.cfg inside core.img
during efi image generation phase (target/linux/install).

This causes grub to not passing kernel command line to the kernel, which
causes kernel panic when the generated gpt image is booted on bios mode
because the kernel doesn't find the root partition.

Fixing the problem involves using minimal grub-early.cfg to embed inside
grub's core.img to load the full-featured grub.cfg later.

grub-early.cfg contains one configuration line:

  configfile (hd0,gpt1)/boot/grub/grub.cfg

With this change, the generated gpt image should be bootable on both
bios and UEFI based systems.

Signed-off-by: Alif M. Ahmad <alive4ever@live.com>
target/linux/x86/image/Makefile

index 495be3670fff15a6b111bcfd22cbac73e166eb83..9f86e2057258a6e3700d22ca1aadeee8e225a858 100644 (file)
@@ -82,13 +82,17 @@ ifneq ($(CONFIG_GRUB_IMAGES)$(CONFIG_EFI_IMAGES),)
                -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
                -e 's#set root.*#search --file /boot/grub/$(SIGNATURE).cfg --set=root#g' \
                ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
+       sed \
+               -e 's/(hd0,msdos1)/(hd0,gpt1)/' ./grub-early.cfg > \
+                       $(KDIR)/root.grub/boot/grub/grub-early.cfg
+
        $(CP) $(KDIR)/root.grub/boot/grub/grub.cfg $(KDIR)/root.grub/boot/grub/$(SIGNATURE).cfg
        grub-mkimage \
                -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
                -o $(KDIR)/grub2/core.img \
                -O i386-pc \
                -p '(hd0,gpt1)/boot/grub' \
-               -c $(KDIR)/root.grub/boot/grub/grub.cfg \
+               -c $(KDIR)/root.grub/boot/grub/grub-early.cfg \
                $(GRUB2_MODULES_LEGACY)
        $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/