common.cfg 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
  2. # GRUB handles (almost) every possible disk setup, but only the location of /boot is actually important,
  3. # since GRUB only loads the user's config. As soon as the kernel takes over, libreboot's done.
  4. # LVM, RAID, filesystems and encryption on both raw devices and partitions in all various combinations
  5. # need to be supported. Since full disk encryption is possible with GRUB as payload and probably desired/used
  6. # by most users, libreboot GRUB config tries to load the operating system (kernel) in the following way:
  7. # 1. Try to decrypt raw devices first. This <your disk setup> inside a LUKS container is pretty common
  8. # a) Try LVM and RAID first, they might be used (accross multiple (raw) devices)
  9. # b) Always try LVM before RAID (LVM on (raw) RAID)
  10. # c) Try MBR/GPT partitions at last, one might still conviniently uses a single partition
  11. for d in (lvm/*) md/0 (md/0,*) ahci0 ahci1 (ahci0,*) (ahci1,*); do
  12. # prompt user for passphrase if LUKS header is found
  13. cryptomount ${d}
  14. done
  15. # (This way, we only need to scan for encrypted data once while covering every possible disk setup,
  16. # be it LVM/BTRFS/ZFS/ext4/etc. (on LUKS) (on RAID) on/across raw devices/MBR/GPT
  17. # 2. Look for user config. If the above routine successfully decrypted a LUKS container, its content
  18. # will be searched before everything else for obvious reasons. Regardless of this, the devices'
  19. # hirachy stays the same.
  20. for d in crypto0 (crypt0,*) (lvm/*) md/0 (md0/,*) ahci0 ahci1 (ahci0,*) (ahci1,*); do
  21. set root=${d}
  22. # a) Check possible file locations...
  23. for p in boot/grub/libreboot_ grub/libreboot_ boot/grub/ grub/ boot/grub2 grub2/; do
  24. if [ -f "/${p}grub.cfg" ]; then
  25. # b) And eventually try to load the config. Using ESC one can still exit and revert back to
  26. # libreboot's menu.
  27. configfile /${p}grub.cfg
  28. fi
  29. done
  30. done
  31. # prompt user for passphrase if LUKS header is found but try using external keyfiles first
  32. search -n -f /keyfile --set=kf --hint usb0, --hint usb1,
  33. if [ $? = 0 ]; then
  34. kf="-k (${kf})/keyfile ${d}"
  35. fi
  36. # (This way, we only need to scan for encrypted data once while covering every possible disk setup,
  37. # be it LVM/BTRFS/ZFS/ext4/etc. (on LUKS) (on RAID) on/across raw devices/MBR/GPT
  38. for d in ${devs}; do
  39. cryptomount ${kf} ${d}
  40. done
  41. # 3. Do the same routine again, but for possibly decrypted data this time. There might be an LVM
  42. # inside the LUKS container, but check crypto0 first since lvm/* also covers already existing (and
  43. # therefore already scanned volumes as well)
  44. for d in crypto0 (crypt0,*) (lvm/*); do
  45. set root=${d}
  46. for p in boot/grub/libreboot_ grub/libreboot_ boot/grub/ grub/ boot/grub2 grub2/; do
  47. if [ -f "/${p}grub.cfg" ]; then
  48. configfile /${p}grub.cfg
  49. fi
  50. done
  51. done
  52. # 3. Last resort, if none of the above succeeds, all you have is GRUB's shell
  53. set root=ahci0,1
  54. for p in / /boot/; do
  55. if [ -f "${p}vmlinuz" ]; then
  56. linux ${p}vmlinuz root=/dev/sda1 rw
  57. if [ -f "${p}initrd.img" ]; then
  58. initrd ${p}initrd.img
  59. fi
  60. fi
  61. done
  62. }
  63. menuentry 'Parse ISOLINUX menu (AHCI) [a]' --hotkey='a' {
  64. for i in 0 1; do
  65. # Check for filesystem on raw device without partition table (MBR/GPT), e.g. BTRFS or ZFS
  66. set root=ahci${i}
  67. for p in /isolinux /syslinux; do
  68. if [ -f "${p}${p}.cfg" ]; then
  69. syslinux_configfile -i ${p}${p}.cfg
  70. elif [ -f "/boot${p}${p}.cfg" ]; then
  71. syslinux_configfile -i /boot${p}${p}.cfg
  72. fi
  73. done
  74. # Look for partitions
  75. # GPT allows more than 4 partitions, /boot on /dev/sda7 is quite unlikely but still possible
  76. for j in 0 1 2 3 4 5 6 7 8 9; do
  77. set root="ahci${i},${j}"
  78. for p in /isolinux /syslinux; do
  79. if [ -f "${p}${p}.cfg" ]; then
  80. syslinux_configfile -i ${p}${p}.cfg
  81. elif [ -f "/boot${p}${p}.cfg" ]; then
  82. syslinux_configfile -i /boot${p}${p}.cfg
  83. fi
  84. done
  85. done
  86. done
  87. }
  88. menuentry 'Parse ISOLINUX menu (USB) [u]' --hotkey='u' {
  89. for i in 0 1; do
  90. # Check for filesystem on raw device without partition table (MBR/GPT), e.g. BTRFS or ZFS
  91. set root=usb${i}
  92. for p in /isolinux /syslinux; do
  93. if [ -f "${p}${p}.cfg" ]; then
  94. syslinux_configfile -i ${p}${p}.cfg
  95. elif [ -f "/boot${p}${p}.cfg" ]; then
  96. syslinux_configfile -i /boot${p}${p}.cfg
  97. fi
  98. done
  99. # Look for partitions
  100. # GPT allows more than 4 partitions, /boot on /dev/sda7 is quite unlikely but still possible
  101. for j in 0 1 2 3 4 5 6 7 8 9; do
  102. set root=usb${i},${j}
  103. for p in "/isolinux" "/syslinux"; do
  104. if [ -f "${p}${p}.cfg" ]; then
  105. syslinux_configfile -i ${p}${p}.cfg
  106. elif [ -f "/boot${p}${p}.cfg" ]; then
  107. syslinux_configfile -i /boot${p}${p}.cfg
  108. fi
  109. done
  110. done
  111. done
  112. }
  113. menuentry 'Parse ISOLINUX menu (CD/DVD) [d]' --hotkey='d' {
  114. insmod ata
  115. for x in ata0 ahci1; do
  116. set root=${x}
  117. for p in "/isolinux" "/syslinux"; do
  118. if [ -f "${p}${p}.cfg" ]; then
  119. syslinux_configfile -i ${p}${p}.cfg
  120. elif [ -f "/boot${p}${p}.cfg" ]; then
  121. syslinux_configfile -i /boot${p}${p}.cfg
  122. fi
  123. done
  124. done
  125. }
  126. menuentry 'Switch to grubtest.cfg [t]' --hotkey='t' {
  127. set root=cbfsdisk
  128. configfile /grubtest.cfg
  129. }
  130. menuentry 'Search for GRUB configuration (grub.cfg) outside of CBFS [s]' --hotkey='s' {
  131. for i in usb0 usb1 ahci0 ahci1; do
  132. for j in 1 2 3 4 5 6 7 8 9; do
  133. x=${i},${j}
  134. for p in "grub" "boot/grub" "grub2" "boot/grub2"; do
  135. if [ -f "${x}/${p}/grub.cfg" ]; then
  136. submenu "Load Config from ${x}" ${x} {
  137. root=$2
  138. source /${p}/grub.cfg
  139. unset superusers
  140. }
  141. fi
  142. done
  143. done
  144. done
  145. }
  146. menuentry 'Poweroff [p]' --hotkey='p' {
  147. halt
  148. }
  149. menuentry 'Reboot [r]' --hotkey='r' {
  150. reboot
  151. }
  152. menuentry 'Load SeaBIOS' {
  153. set root='cbfsdisk'
  154. chainloader /bios.bin.elf
  155. }