common.cfg 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. function try_user_config {
  2. set root="${1}"
  3. for dir in boot grub grub2 boot/grub boot/grub2; do
  4. for name in '' autoboot_ libreboot_ coreboot_; do
  5. if [ -f /"${dir}"/"${name}"grub.cfg ]; then
  6. unset superusers
  7. configfile /"${dir}"/"${name}"grub.cfg
  8. fi
  9. done
  10. done
  11. }
  12. function search_grub {
  13. for i in 0 1; do
  14. # raw devices
  15. try_user_config "(${1}${i})"
  16. for part in 1 2 3 4 5; do
  17. # MBR/GPT partitions
  18. try_user_config "(${1}${i},${part})"
  19. done
  20. done
  21. }
  22. function try_isolinux_config {
  23. set root="${1}"
  24. for dir in '' /boot; do
  25. if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
  26. syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
  27. elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
  28. syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
  29. fi
  30. done
  31. }
  32. function search_isolinux {
  33. for i in 0 1; do
  34. # raw devices
  35. try_isolinux_config "(${1}${i})"
  36. for part in 1 2 3 4 5; do
  37. # MBR/GPT partitions
  38. try_isolinux_config "(${1}${i},${part})"
  39. done
  40. done
  41. }
  42. menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
  43. # GRUB2 handles (almost) every possible disk setup, but only the location of
  44. # /boot is actually important since GRUB2 only loads the user's config.
  45. # LVM, RAID, filesystems and encryption on both raw devices and partitions in
  46. # all various combinations need to be supported. Since full disk encryption is
  47. # possible with GRUB2 as payload and probably even used by most users, this
  48. # configuration tries to load the operating system in the following way:
  49. # 1. Look for user configuration on unencrypted devices first to avoid
  50. # unnecessary decryption routines in the following order:
  51. # 1) raw devices and MBR/GPT partitions
  52. search_grub ahci
  53. search_grub ata
  54. # 2) LVM and RAID which might be used accross multiple devices
  55. lvm="lvm/matrix-rootvol lvm/matrix-boot"
  56. raid="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
  57. for vol in ${lvm} ${raid}; do
  58. try_user_config "(${vol})"
  59. done
  60. # 2. In case no configuration could be found, try decrypting devices. Look
  61. # on raw crypto devices as well as inside LVM volumes this time.
  62. # The user will be prompted for a passphrase if a LUKS header was found.
  63. for dev in ahci0 ata0 ${lvm}; do
  64. cryptomount "(${dev})"
  65. done
  66. # 3) encrypted devices/partitions
  67. for i in 0 1; do
  68. for part in 1 2 3 4 5; do
  69. for type in ahci ata; do
  70. cryptomount "(${type}${i},${part})"
  71. done
  72. done
  73. done
  74. # 3) encrypted devices/partitions
  75. search_grub crypto
  76. # 4) LVM inside LUKS containers
  77. for vol in ${lvm}; do
  78. try_user_config "(${vol})"
  79. done
  80. # Last resort, if all else fails
  81. set root=ahci0,1
  82. for p in / /boot/; do
  83. if [ -f "${p}vmlinuz" ]; then
  84. linux ${p}vmlinuz root=/dev/sda1 rw
  85. if [ -f "${p}initrd.img" ]; then
  86. initrd ${p}initrd.img
  87. fi
  88. fi
  89. done
  90. # Last resort (for GA-G41-ES2L which uses IDE emulation mode for SATA)
  91. set root=ata0,1
  92. for p in / /boot/; do
  93. if [ -f "${p}vmlinuz" ]; then
  94. linux ${p}vmlinuz root=/dev/sda1 rw
  95. if [ -f "${p}initrd.img" ]; then
  96. initrd ${p}initrd.img
  97. fi
  98. fi
  99. done
  100. }
  101. menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
  102. search_isolinux ahci
  103. }
  104. menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
  105. search_isolinux usb
  106. }
  107. menuentry 'Search ISOLINUX menu (CD/DVD) [d]' --hotkey='d' {
  108. insmod ata
  109. for dev in ata0 ata1 ata2 ata3 ahci1; do
  110. try_isolinux_config "(${dev})"
  111. done
  112. }
  113. menuentry 'Load test configuration (grubtest.cfg) inside of CBFS [t]' --hotkey='t' {
  114. set root='(cbfsdisk)'
  115. configfile /grubtest.cfg
  116. }
  117. menuentry 'Search for GRUB2 configuration on external media [s]' --hotkey='s' {
  118. search_grub usb
  119. }
  120. menuentry 'Poweroff [p]' --hotkey='p' {
  121. halt
  122. }
  123. menuentry 'Reboot [r]' --hotkey='r' {
  124. reboot
  125. }