grub.cfg 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. set prefix=(memdisk)/boot/grub
  2. insmod nativedisk
  3. insmod ehci
  4. insmod ohci
  5. insmod uhci
  6. insmod usb
  7. insmod usbms
  8. insmod usbserial_pl2303
  9. insmod usbserial_ftdi
  10. insmod usbserial_usbdebug
  11. # Serial and keyboard configuration, very important.
  12. serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
  13. terminal_input --append serial
  14. terminal_output --append serial
  15. terminal_input --append at_keyboard
  16. terminal_output --append cbmemc
  17. gfxpayload=keep
  18. terminal_output --append gfxterm
  19. # Default to first option, automatically boot after 1 second
  20. set default="0"
  21. set timeout=1
  22. # This is useful when using 'cat' on long files on GRUB terminal
  23. set pager=1
  24. function try_user_config {
  25. set root="${1}"
  26. for dir in boot grub grub2 boot/grub boot/grub2; do
  27. for name in libreboot_ autoboot_ librecore_ coreboot_ ''; do
  28. if [ -f /"${dir}"/"${name}"grub.cfg ]; then
  29. unset superusers
  30. configfile /"${dir}"/"${name}"grub.cfg
  31. fi
  32. done
  33. done
  34. }
  35. function search_grub {
  36. for i in 0 1; do
  37. # raw devices
  38. try_user_config "(${1}${i})"
  39. for part in 1 2 3 4 5; do
  40. # MBR/GPT partitions
  41. try_user_config "(${1}${i},${part})"
  42. done
  43. done
  44. }
  45. function try_isolinux_config {
  46. set root="${1}"
  47. for dir in '' /boot; do
  48. if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
  49. syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
  50. elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
  51. syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
  52. fi
  53. done
  54. }
  55. function search_isolinux {
  56. for i in 0 1; do
  57. # raw devices
  58. try_isolinux_config "(${1}${i})"
  59. for part in 1 2 3 4 5; do
  60. # MBR/GPT partitions
  61. try_isolinux_config "(${1}${i},${part})"
  62. done
  63. done
  64. }
  65. menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
  66. # GRUB2 handles (almost) every possible disk setup, but only the location of
  67. # /boot is actually important since GRUB2 only loads the user's config.
  68. # LVM, RAID, filesystems and encryption on both raw devices and partitions in
  69. # all various combinations need to be supported. Since full disk encryption is
  70. # possible with GRUB2 as payload and probably even used by most users, this
  71. # configuration tries to load the operating system in the following way:
  72. # 1. Look for user configuration on unencrypted devices first to avoid
  73. # unnecessary decryption routines in the following order:
  74. # 1) raw devices and MBR/GPT partitions
  75. search_grub ahci
  76. search_grub ata
  77. # 2) LVM and RAID which might be used accross multiple devices
  78. lvm="lvm/matrix-rootvol lvm/matrix-boot"
  79. raid="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
  80. for vol in ${lvm} ${raid}; do
  81. try_user_config "(${vol})"
  82. done
  83. # 2. In case no configuration could be found, try decrypting devices. Look
  84. # on raw crypto devices as well as inside LVM volumes this time.
  85. # The user will be prompted for a passphrase if a LUKS header was found.
  86. for dev in ahci0 ata0 usb0 ${lvm}; do
  87. cryptomount "(${dev})"
  88. done
  89. # 3) encrypted devices/partitions
  90. for i in 0 1; do
  91. for part in 1 2 3 4 5; do
  92. for type in ahci ata; do
  93. cryptomount "(${type}${i},${part})"
  94. done
  95. done
  96. done
  97. # 3) encrypted devices/partitions
  98. search_grub crypto
  99. # 4) LVM inside LUKS containers
  100. for vol in ${lvm}; do
  101. try_user_config "(${vol})"
  102. done
  103. # Last resort, if all else fails
  104. set root=ahci0,1
  105. for p in / /boot/; do
  106. if [ -f "${p}vmlinuz" ]; then
  107. linux ${p}vmlinuz root=/dev/sda1 rw
  108. if [ -f "${p}initrd.img" ]; then
  109. initrd ${p}initrd.img
  110. fi
  111. fi
  112. done
  113. # Last resort (for GA-G41-ES2L which uses IDE emulation mode for SATA)
  114. set root=ata0,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. }
  124. menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
  125. search_isolinux ahci
  126. }
  127. menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
  128. search_isolinux usb
  129. }
  130. menuentry 'Search ISOLINUX menu (CD/DVD) [d]' --hotkey='d' {
  131. insmod ata
  132. for dev in ata0 ata1 ata2 ata3 ahci1; do
  133. try_isolinux_config "(${dev})"
  134. done
  135. }
  136. menuentry 'Load test configuration (grubtest.cfg) inside of CBFS [t]' --hotkey='t' {
  137. set root='(cbfsdisk)'
  138. configfile /grubtest.cfg
  139. }
  140. menuentry 'Search for GRUB2 configuration on external media [s]' --hotkey='s' {
  141. search_grub usb
  142. }
  143. menuentry 'Load MemTest86+ [m]' --hotkey='m' {
  144. linux16 (cbfsdisk)/memtest.bin
  145. }
  146. menuentry 'Poweroff [p]' --hotkey='p' {
  147. halt
  148. }
  149. menuentry 'Reboot [r]' --hotkey='r' {
  150. reboot
  151. }