grub.cfg 4.5 KB

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