]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
update-bootloader: Extend script to support EFI
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Jul 2018 11:34:55 +0000 (11:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Jul 2018 12:03:09 +0000 (12:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/update-bootloader

index ad6fdb6420a600ab6c7e5f16172aec45076f25d6..64b0e125bd5546973acb9b13712c15de42192d7e 100644 (file)
@@ -21,7 +21,7 @@
 #                                                                          #
 ############################################################################
 
-GRUB_INSTALL_ARGS="--no-floppy --recheck"
+GRUB_INSTALL_ARGS="--no-floppy --recheck --force"
 
 function find_bootloader_device() {
        local mp
@@ -99,15 +99,54 @@ function grub_install() {
                return 1
        fi
 
-       local args
-       for args in "" "--force"; do
-               if grub-install ${GRUB_INSTALL_ARGS} ${args} "${device}" &>/dev/null; then
-                       return 0
-               fi
+       local arches
+       case "$(uname -m)" in
+               aarch64)
+                       arches="arm64-efi"
+                       ;;
+               i?86)
+                       arches="i386-pc"
+                       ;;
+               x86_64)
+                       arches="i386-pc x86_64-efi"
+                       ;;
+       esac
+
+       local arch
+       for arch in ${arches}; do
+               local args="--target=${arch}"
+
+               case "${arch}" in
+                       *-efi)
+                               # Skip all EFI architectures if no EFI partition exists
+                               if [ ! -d "/boot/efi" ]; then
+                                       continue
+                               fi
+
+                               args="${args} --efi-directory=/boot/efi"
+
+                               # Don't try to modify the BIOS when we are
+                               # not running on EFI right now
+                               if [ ! -d "/sys/firmware/efi" ]; then
+                                       args="${args} --no-nvram"
+                               fi
+                               ;;
+               esac
+
+               local removable
+               for removable in "" "--removable"; do
+                       if ! grub-install ${GRUB_INSTALL_ARGS} ${args} \
+                                       ${removable} "${device}" &>/dev/null; then
+                               echo "Could not install GRUB on ${device}" >&2
+                               return 1
+                       fi
+
+                       # Do not try to install with --removable for non-efi architectures
+                       [[ "${arch}" =~ \-efi$ ]] || break
+               done
        done
 
-       echo "Could not install GRUB on ${device}" >&2
-       return 1
+       return 0
 }
 
 function main() {