OSDN Git Service

Try to boot more OSes from other ESP
authorChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 8 Feb 2018 10:22:02 +0000 (18:22 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 8 Feb 2018 10:22:02 +0000 (18:22 +0800)
Search more boot loaders including the default and fallback from
other possible EFI system partition.

install/grub2/efi/boot/android.cfg

index 6292e9c..dae2a57 100644 (file)
@@ -14,13 +14,17 @@ function add_entry {
 # $2 OS name
 # $3 Class
 function add_os_if_exists {
-#      search --no-floppy --set -f $1
-       if [ -e ($root)/$1 ]; then
-               menuentry "$2 ->" "$1" --class "$3" {
-                       savedefault
-                       chainloader ($root)/$2
-               }
-       fi
+       # Is there a better way to find ESP?
+       for d in hd0,gpt1 hd0,gpt2 hd1,gpt1 hd1,gpt2 hd0,msdos1 hd0,msdos2 hd1,msdos1 hd1,msdos2; do
+               if [ "($d)$1" != "$cmdpath/$bootefi" -a -e ($d)$1 ]; then
+                       menuentry "$2 at $d ->" "$d" "$1" --class "$3" {
+                               savedefault
+                               set root=$2
+                               chainloader ($root)$3
+                       }
+                       break
+               fi
+       done
 }
 
 function savedefault {
@@ -34,8 +38,16 @@ if [ -s $prefix/grubenv ]; then
        load_env
 fi
 
+if [ "$grub_cpu" = "i386" ]; then
+       set bootefi=bootia32.efi
+       set grub=grubia32
+else
+       set bootefi=BOOTx64.EFI
+       set grub=grubx64
+fi
+
 search --no-floppy --set android -f $kdir/kernel
-export android kdir live src
+export android bootefi grub kdir live src
 
 # Create main menu
 add_entry "$live" quiet
@@ -50,22 +62,22 @@ submenu "Advanced options -> " {
                add_entry "Auto Install to specified harddisk" AUTO_INSTALL=0
                add_entry "Auto Update" AUTO_INSTALL=update
        fi
+       add_os_if_exists /EFI/BOOT/$bootefi "UEFI OS"
+       add_os_if_exists /EFI/BOOT/fallback.efi "UEFI Fallback"
        if [ "$grub_cpu" != "i386" ]; then
+               add_os_if_exists /EFI/BOOT/fallback_x64.efi "UEFI Fallback"
                menuentry "Reboot" { reboot }
                menuentry "Poweroff" { halt }
                menuentry "UEFI BIOS Setup" { fwsetup }
        fi
 }
 
-if [ "$grub_cpu" = "i386" ]; then
-       set grub=grubia32
-else
-       set grub=grubx64
-fi
-
 # Add other OSes boot loaders if exist
 add_os_if_exists /EFI/fedora/${grub}.efi Fedora fedora
+add_os_if_exists /EFI/centos/${grub}.efi CentOS centos
 add_os_if_exists /EFI/ubuntu/${grub}.efi Ubuntu ubuntu
+add_os_if_exists /EFI/debian/${grub}.efi Debian debian
+add_os_if_exists /EFI/linuxmint/${grub}.efi "Linux Mint" linuxmint
 add_os_if_exists /EFI/Microsoft/Boot/bootmgfw.efi Windows windows
 
 for d in $config_directory $cmdpath $prefix; do