grub.cfg 4.4 KB

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