30_uefi-firmware-new 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #! /bin/sh
  2. set -e
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2012 Free Software Foundation, Inc.
  5. #
  6. # GRUB is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # GRUB is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. prefix="/usr"
  19. exec_prefix="/usr"
  20. datarootdir="/usr/share"
  21. export TEXTDOMAIN=grub
  22. export TEXTDOMAINDIR="${datarootdir}/locale"
  23. . "${datarootdir}/grub/grub-mkconfig_lib"
  24. efi_vars_dir=/sys/firmware/efi/efivars
  25. EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c
  26. OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE"
  27. if [ -e "$OsIndications" ] && \
  28. [ "$(( $(printf 0x%x \'"$(cat $OsIndications | cut -b1)") & 1 ))" = 1 ]; then
  29. LABEL="System setup"
  30. gettext_printf "Adding boot menu entry for EFI firmware configuration\n" >&2
  31. onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  32. cat << EOF
  33. if [ "\$grub_platform" = "efi" ]; then
  34. fwsetup --is-supported
  35. if [ "\$?" = 0 ]; then
  36. menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
  37. fwsetup
  38. }
  39. fi
  40. fi
  41. EOF
  42. fi
  43. #See for EFI present
  44. if [ -d /sys/firmware/efi ]; then
  45. . "/usr/share/grub/grub-mkconfig_lib"
  46. #See for Windows EFI string in EFI BIOS
  47. WINDOWS_EFI=$(/usr/sbin/efibootmgr -v | grep -E -m 1 '(WINDOWS|Windows Boot Manager)' | sed 's/.*\(HD([^()]*)File([^()]*)\).*/\1/i')
  48. if [ -z "$WINDOWS_EFI" ]; then
  49. exit 0
  50. fi
  51. WIN_EFI_PATH_LINUX=/EFI/Microsoft/Boot/bootmgfw.efi
  52. #Determine EFI UUID
  53. WIN_EFI_UUID=$(grub2-probe --target=fs_uuid /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi)
  54. ESP_SEARCH_HINTS=$(grub2-probe --target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi)
  55. cat << EOF
  56. menuentry "Windows Boot Manager" {
  57. EOF
  58. save_default_entry | sed -e "s/^/ /"
  59. cat << EOF
  60. insmod part_gpt
  61. insmod fat
  62. insmod search_fs_uuid
  63. insmod chain
  64. search --fs-uuid --set=root ${ESP_SEARCH_HINTS} ${WIN_EFI_UUID}
  65. chainloader $WIN_EFI_PATH_LINUX
  66. }
  67. EOF
  68. fi