grub.cfg: clean up comments

fsdg20230625
Leah Rowe 2021-12-29 06:04:42 +00:00
parent c98308c499
commit bbdb9512f3
1 changed files with 10 additions and 52 deletions

View File

@ -10,7 +10,6 @@ insmod usb
insmod usbms
insmod regexp
# Serial and keyboard configuration, very important.
terminal_input --append at_keyboard
terminal_input --append usb_keyboard
terminal_output --append cbmemc
@ -26,11 +25,8 @@ elif [ -f (cbfsdisk)/background.jpg ]; then
background_image (cbfsdisk)/background.jpg
fi
# Default to first option, automatically boot after 1 second
set default="0"
set timeout=10
# This is useful when using 'cat' on long files on GRUB terminal
set pager=1
keymap usqwerty
@ -47,19 +43,13 @@ function try_user_config {
}
function search_grub {
echo -n "Attempting to load grub.cfg from: "
# TODO : Find a better way to detect how many disks
# : are on the computer instead of hardcoding.
# FIXME: Does this work on all boards?
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
# TODO : Find a better way to detect how many partitions
# : are on the disk instead of hardcoding.
echo "\nTrying disk ${1}${i}"
for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
# MBR/GPT partitions
echo "\nTrying partiton ${part}"
try_user_config "(${1}${i},${part})"
done
# raw devices
# raw devices e.g. (ahci0) instead of (ahci0,1)
echo "\nTrying to boot to a raw disk ..."
try_user_config "(${1}${i})"
echo # Insert newline
@ -78,15 +68,12 @@ function try_isolinux_config {
}
function search_isolinux {
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
# TODO : Find a better way to detect how many partitions
# : are on the disk instead of hardcoding.
echo "\nAttempting to parse isolinux menu from ${1}${i}"
for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
# MBR/GPT partitions
echo "\nTrying partiton ${part}"
try_isolinux_config "(${1}${i},${part})"
done
# raw devices
# raw devices e.g. (usb0) instead of (usb0,1)
echo "\nTrying raw usb device ..."
try_isolinux_config "(${1}${i})"
echo # Insert newline
@ -94,47 +81,24 @@ function search_isolinux {
}
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
# GRUB2 handles (almost) every possible disk setup, but only the location of
# /boot is actually important since GRUB2 only loads the user's config.
# LVM, RAID, filesystems and encryption on both raw devices and partitions in
# all various combinations need to be supported. Since full disk encryption is
# possible with GRUB2 as payload and probably even used by most users, this
# configuration tries to load the operating system in the following way:
# 1. Look for user configuration on unencrypted devices first to avoid
# unnecessary decryption routines in the following order:
# 1) raw devices and MBR/GPT partitions
search_grub ahci
search_grub ata
# 2) LVM and RAID which might be used accross multiple devices
lvmvol="lvm/matrix-bootvol lvm/matrix-rootvol"
# TODO: add more entries to this string in the future, with common
# volume group names per common distro configs. look at what all the
# popular distros are doing when the user select automatic partitioning
# in their distro's installer. this still won't cover all use cases,
# but grub's enumeration of anything partition-related is very slow,
# so for now we hardcode everything in grub.cfg
# again, hardcoded. grub's enumeration is always very slow.
# until that is optimized, we must hardcode everything in grub.cfg
# grub device enumeration is very slow, so checks are hardcoded
# TODO: add more strings, based on what distros set up when
# the user select auto-partitioning on those installers
lvmvol="lvm/matrix-bootvol lvm/matrix-rootvol"
raidvol="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
# in practise, doing multiple redundant checks is perfectly fast and
# ok, even if less technically correct
# TODO: optimize grub itself, and use */? here for everything
for vol in ${lvmvol} ${raidvol} ; do
try_user_config "${vol}"
done
# 2. In case no configuration could be found, try decrypting devices. Look
# on raw crypto devices as well as inside LVM volumes this time.
# The user will be prompted for a passphrase if a LUKS header was found.
# Encrypted disks and partitions
#TODO: This needs to be adjusted on each device to exclude ODD
#TODO: Usually ATA is for odd if both exist!
unset ahcidev
unset atadev
for i in 11 10 9 8 7 6 5 4 3 2 1 0; do
@ -151,21 +115,15 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o
if cryptomount "${dev}" ; then break ; fi
done
set pager=1
echo # Insert newline
echo
# Retry lvm volumes, because after cryptomount, they might now be exposed
# 3) LVM inside LUKS containers
# after cryptomount, lvm volumes might be available
for vol in ${lvmvol}; do
try_user_config "${vol}"
done
# 4) encrypted devices/partitions
search_grub crypto
# TODO: generalize last resorts
# Use first connected device? not just sata port 1
# Last resort, if all else fails
set root=ahci0,1
for p in / /boot/; do