[PATCH 1/2] x86: fix bios mkimage during efi image generation
(too old to reply)
Alif M. Ahmad
2018-03-04 01:40:21 UTC
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 <***@live.com>

This patch is based on Jow's staging repository instead of OpenWrt master branch.

Hopefully, this would allow UEFI image generation for x86 targets, i.e. to get
changes on Jow's staging repository merged into OpenWrt master branch

target/linux/x86/image/Makefile | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
index d5786fb2ad..c8dd94dc78 100644
--- a/target/linux/x86/image/Makefile
+++ b/target/linux/x86/image/Makefile
@@ -86,13 +86,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 \
$(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
Jo-Philipp Wich
2018-03-14 18:18:10 UTC
Merged into my staging tree at

Thank you!
Alif M. Ahmad
2018-03-16 01:53:36 UTC
Post by Jo-Philipp Wich
Merged into my staging tree at
Thank you!
The next patch in series is not yet applied.

My reason to simplify the image generation is as follows.
1. grub-bios-setup on ptgen-generated disk image is really unnecessary,
since the resulting image will be converted to gpt later. No need for
mbr boot sector here, since grub will use BIOS boot partition (EF02)
instead of MBR when the performing grub-bios-install on the gpt disk

Avoiding grub-bios-setup before gpt image has been generated saves
several seconds on target/linux/install as well.

Actually, grub-bios-install behaves the same to grub-bios-install-efi:
setting up bios boot loader for legacy bios boot for both gpt and mbr

2. There is no need to have 3 grub configurations.

The previous fix for bios mkimage leaves grub-early.cfg inside
/boot/grub. There is a cleanup performed on the next patch to remove
grub-early.cfg, since it has been embedded inside grub-core.img.

The grub-early.cfg should also be embedded for bootx64.efi, similar to
how grub-early.cfg is embedded for bios core.img, so the resulting gpt
image will have identical grub configuration for both bios and efi

With grub-early.cfg embedded inside bootx64.efi, the $(SIGNATURE).cfg is
not needed anymore. grub.cfg is available and the content of
$(SIGNATURE).cfg is identical to grub.cfg.