x86: grub2: search for the "kernel" filesystem on all disks
authorJax Jiang <jax.jiang.007@gmail.com>
Thu, 10 Feb 2022 17:46:55 +0000 (01:46 +0800)
committerChristian Lamparter <chunkeey@gmail.com>
Thu, 24 Feb 2022 19:45:12 +0000 (20:45 +0100)
Previously, grub2 was hardcoded to always look on "hd0" for the
kernel.

This works well when the system only had a single disk.
But if there was a second disk/stick present, it may have look
on the wrong drive because of enumeration races.

This patch utilizes grub2 search function to look for a filesystem
with the label "kernel". This works thanks to existing setup in
scripts/gen_image_generic.sh. Which sets the "kernel" label on
both the fat and ext4 filesystem variants.

Signed-off-by: Jax Jiang <jax.jiang.007@gmail.com>
Suggested-by: Alberto Bursi <bobafetthotmail@gmail.com> (MX100 WA)
(word wrapped, slightly rewritten commit message, removed MX100 WA)
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
package/boot/grub2/Makefile
target/linux/x86/base-files/lib/upgrade/platform.sh
target/linux/x86/image/grub-efi.cfg

index 9c67ff589b1864cc6cb5f42572f93092b439cb22..67b36842ecdb2ec9f917db53c944bd0e366acec6 100644 (file)
@@ -120,28 +120,28 @@ define Package/grub2/install
                -O i386-pc \
                -c $(PKG_BUILD_DIR)/grub-early.cfg \
                -o $(STAGING_DIR_IMAGE)/grub2/gpt-core.img \
-               at_keyboard biosdisk boot chain configfile fat linux ls part_gpt reboot serial vga
+               at_keyboard biosdisk boot chain configfile fat linux ls part_gpt reboot search serial vga
        $(STAGING_DIR_HOST)/bin/grub-mkimage \
                -d $(PKG_BUILD_DIR)/grub-core \
                -p /boot/grub \
                -O i386-pc \
                -c ./files/grub-early.cfg \
                -o $(STAGING_DIR_IMAGE)/grub2/generic-core.img \
-               at_keyboard biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
+               at_keyboard biosdisk boot chain configfile ext2 linux ls part_msdos reboot search serial vga
        $(STAGING_DIR_HOST)/bin/grub-mkimage \
                -d $(PKG_BUILD_DIR)/grub-core \
                -p /boot/grub \
                -O i386-pc \
                -c ./files/grub-early.cfg \
                -o $(STAGING_DIR_IMAGE)/grub2/eltorito.img \
-               at_keyboard biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga
+               at_keyboard biosdisk boot chain configfile iso9660 linux ls part_msdos reboot search serial test vga
        $(STAGING_DIR_HOST)/bin/grub-mkimage \
                -d $(PKG_BUILD_DIR)/grub-core \
                -p /boot/grub \
                -O i386-pc \
                -c ./files/grub-early.cfg \
                -o $(STAGING_DIR_IMAGE)/grub2/legacy-core.img \
-               biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
+               biosdisk boot chain configfile ext2 linux ls part_msdos reboot search serial vga
 endef
 
 define Package/grub2-efi/install
index 94bf80b144d30c7223da5f13d681009f3d12aa75..d8f2eba97ecbab9c18ddd82ba4a37a37485896f4 100644 (file)
@@ -65,16 +65,6 @@ platform_do_bootloader_upgrade() {
                        "/dev/$diskdev" \
                && touch /tmp/boot/boot/grub/upgraded
 
-        case "$(board_name)" in
-        cisco-mx100-hw)
-            # If the MX100 is booted UEFI AND the SATA HDD exists, we need to change
-            # grub's root= to hd1 for it to boot correctly, otherwise we can keep it hd0.
-            if [ -d /sys/firmware/efi ] && [ "$(ls -a /dev/sd[a-z] | wc -w)" -gt 1 ] ; then
-                sed -i "s|hd0,${parttable}1|hd1,${parttable}1|g" /tmp/boot/boot/grub/grub.cfg
-            fi
-            ;;
-        esac
-
                umount /tmp/boot
        fi
 }
index 14d30e88e4642b8e649b3b355d153eab7301dacd..bbb31f7747b0fb8872a12898bc9166d5e794bab5 100644 (file)
@@ -3,7 +3,7 @@
 
 set default="0"
 set timeout="@TIMEOUT@"
-set root='(hd0,gpt1)'
+search -l kernel -s root
 
 menuentry "@TITLE@" {
        linux /boot/vmlinuz @GPT_ROOTPART@ @CMDLINE@ noinitrd