grub.cfg 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. set prefix=(memdisk)/boot/grub
  2. insmod at_keyboard
  3. insmod usb_keyboard
  4. insmod nativedisk
  5. insmod ehci
  6. insmod ohci
  7. insmod uhci
  8. insmod usb
  9. insmod usbms
  10. insmod regexp
  11. terminal_input --append at_keyboard
  12. terminal_input --append usb_keyboard
  13. terminal_output --append cbmemc
  14. gfxpayload=keep
  15. terminal_output --append gfxterm
  16. if [ -f (cbfsdisk)/background.png ]; then
  17. insmod png
  18. background_image (cbfsdisk)/background.png
  19. elif [ -f (cbfsdisk)/background.jpg ]; then
  20. insmod jpeg
  21. background_image (cbfsdisk)/background.jpg
  22. fi
  23. set default="0"
  24. set timeout=10
  25. set pager=1
  26. set grub_scan_disk="both"
  27. keymap usqwerty
  28. function try_user_config {
  29. set root="${1}"
  30. for dir in boot grub grub2 boot/grub boot/grub2; do
  31. for name in '' osboot_ autoboot_ libreboot_ coreboot_; do
  32. if [ -f /"${dir}"/"${name}"grub.cfg ]; then
  33. unset superusers
  34. configfile /"${dir}"/"${name}"grub.cfg
  35. fi
  36. done
  37. done
  38. }
  39. function search_grub {
  40. echo -n "Attempting to load grub.cfg from '${1}' devices"
  41. for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
  42. for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
  43. try_user_config "(${1}${i},${part})"
  44. done
  45. # raw devices e.g. (ahci0) instead of (ahci0,1)
  46. try_user_config "(${1}${i})"
  47. done
  48. echo # Insert newline
  49. }
  50. function try_isolinux_config {
  51. set root="${1}"
  52. for dir in '' /boot; do
  53. if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
  54. syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
  55. elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
  56. syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
  57. fi
  58. done
  59. }
  60. function search_isolinux {
  61. echo "\nAttempting to parse isolinux/syslinux config from '${1}' devices"
  62. for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
  63. for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
  64. try_isolinux_config "(${1}${i},${part})"
  65. done
  66. # raw devices e.g. (usb0) instead of (usb0,1)
  67. try_isolinux_config "(${1}${i})"
  68. done
  69. echo # Insert newline
  70. }
  71. menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
  72. if [ "${grub_scan_disk}" != "ata" ]; then
  73. search_grub ahci
  74. fi
  75. if [ "${grub_scan_disk}" != "ahci" ]; then
  76. search_grub ata
  77. fi
  78. # grub device enumeration is very slow, so checks are hardcoded
  79. # TODO: add more strings, based on what distros set up when
  80. # the user select auto-partitioning on those installers
  81. lvmvol="lvm/matrix-bootvol lvm/matrix-rootvol"
  82. raidvol="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
  83. # in practise, doing multiple redundant checks is perfectly fast and
  84. # TODO: optimize grub itself, and use */? here for everything
  85. for vol in ${lvmvol} ${raidvol} ; do
  86. try_user_config "${vol}"
  87. done
  88. unset ahcidev
  89. unset atadev
  90. for i in 11 10 9 8 7 6 5 4 3 2 1 0; do
  91. for part in 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1; do
  92. if [ "${grub_scan_disk}" != "ata" ]; then
  93. ahcidev="(ahci${i},${part}) ${ahcidev}"
  94. fi
  95. if [ "${grub_scan_disk}" != "ahci" ]; then
  96. atadev="(ata${i},${part}) ${atadev}"
  97. fi
  98. done
  99. done
  100. set pager=0
  101. echo -n "Attempting to unlock encrypted volumes"
  102. for dev in ${ahcidev} ${atadev} ${lvmvol} ${raidvol}; do
  103. if cryptomount "${dev}" ; then break ; fi
  104. done
  105. set pager=1
  106. echo
  107. # after cryptomount, lvm volumes might be available
  108. for vol in ${lvmvol}; do
  109. try_user_config "${vol}"
  110. done
  111. search_grub crypto
  112. if [ "${grub_scan_disk}" != "ata" ]; then
  113. # Last resort, if all else fails
  114. set root=ahci0,1
  115. for p in / /boot/; do
  116. if [ -f "${p}vmlinuz" ]; then
  117. linux ${p}vmlinuz root=/dev/sda1 rw
  118. if [ -f "${p}initrd.img" ]; then
  119. initrd ${p}initrd.img
  120. fi
  121. fi
  122. done
  123. fi
  124. if [ "${grub_scan_disk}" != "ahci" ]; then
  125. # Last resort (for setups that use IDE instead of SATA)
  126. set root=ata0,1
  127. for p in / /boot/; do
  128. if [ -f "${p}vmlinuz" ]; then
  129. linux ${p}vmlinuz root=/dev/sda1 rw
  130. if [ -f "${p}initrd.img" ]; then
  131. initrd ${p}initrd.img
  132. fi
  133. fi
  134. done
  135. fi
  136. true # Prevent pager requiring to accept each line instead of whole screen
  137. }
  138. menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
  139. search_isolinux ahci
  140. }
  141. menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
  142. search_isolinux usb
  143. }
  144. menuentry 'Search ISOLINUX menu (ATA/IDE) [d]' --hotkey='d' {
  145. search_isolinux ata
  146. }
  147. menuentry 'Load test configuration (grubtest.cfg) inside of CBFS [t]' --hotkey='t' {
  148. set root='(cbfsdisk)'
  149. if [ -f /grubtest.cfg ]; then
  150. configfile /grubtest.cfg
  151. fi
  152. }
  153. menuentry 'Search for GRUB2 configuration on external media [s]' --hotkey='s' {
  154. search_grub usb
  155. }
  156. if [ -f (cbfsdisk)/seabios.elf ]; then
  157. menuentry 'Load SeaBIOS (payload) [b]' --hotkey='b' {
  158. set root='cbfsdisk'
  159. chainloader /seabios.elf
  160. }
  161. fi
  162. if [ -f (cbfsdisk)/img/grub2 ]; then
  163. menuentry 'Return to SeaBIOS [b]' --hotkey='b' {
  164. set root='cbfsdisk'
  165. chainloader /fallback/payload
  166. }
  167. fi
  168. menuentry 'Poweroff [p]' --hotkey='p' {
  169. halt
  170. }
  171. menuentry 'Reboot [r]' --hotkey='r' {
  172. reboot
  173. }
  174. if [ -f (cbfsdisk)/img/memtest ]; then
  175. menuentry 'Load MemTest86+ [m]' --hotkey='m' {
  176. set root='cbfsdisk'
  177. chainloader /img/memtest
  178. }
  179. fi