grub.cfg: support ESP, btrfs subvols and extlinux
This is backported from lbmk at revision: 09bed9a4c3257dbf9b4d59975db0071472ed67eb In comparison to the GNU Boot configuration, Libreboot's GRUB configuration provides the following improvements: * Support for scanning of BTRFS sub volumes, on most setups. * Support for scanning syslinux and extlinux configs, in the main "Load Operating System" menuentry. This will make distros automatically boot in most cases, where they use extlinux/syslinux instead of GRUB. * Support for scanning EFI System Partitions, when scanning for GRUB, Syslinux and Extlinux configuration files. This adds support for UEFI-based distro installations; the GNU Boot supported mainboards are all BIOS-based, but the user may have transferred an HDD/SSD from another system, where UEFI was used. On UEFI-based systems, there is a special FAT partition called the ESP (EFI System Partition) that boot loaders and configurations are installed to. * The ESP support is also extended to USB-based booting. This increases support out of the box for more distro installers, many of which are now UEFI-only, or only well-tested for UEFI. Many distros today now use *GRUB* (built for UEFI) on their install media, but these can also be used on bare metal setups such as GNU Boot's GRUB payload. * The fallback entry was removed, that assumed /dev/sda1 as the root partition; where scanning of GRUB configurations failed, GNU Boot GRUB would try this fallback logic, but such logic may in some cases result in the system being booted, in such a way that *breaks* the user's distro, so it's better that GNU Boot only scan for GRUB/Extlinux/Syslinux configs and return with an error if none are found. This is also how Libreboot does it nowadays. With this, and the previous patches that I've committed, GNU Boot's GRUB setup should now be in feature parity with Lbreboot. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
parent
d7372a620b
commit
536d8ac919
1 changed files with 34 additions and 43 deletions
|
@ -33,7 +33,9 @@ set grub_scan_disk="both"
|
|||
keymap usqwerty
|
||||
function try_user_config {
|
||||
set root="${1}"
|
||||
for dir in boot grub grub2 boot/grub boot/grub2; do
|
||||
|
||||
# The @/... entries are for cases where the BTRFS filesystem is being used
|
||||
for dir in boot grub grub2 boot/grub boot/grub2 @/boot @/grub @/grub2 @/boot/grub @/boot/grub2; do
|
||||
for name in '' gnuboot_ osboot_ autoboot_ coreboot_; do
|
||||
if [ -f /"${dir}"/"${name}"grub.cfg ]; then
|
||||
unset superusers
|
||||
|
@ -56,16 +58,20 @@ function search_grub {
|
|||
|
||||
function try_isolinux_config {
|
||||
set root="${1}"
|
||||
for dir in '' /boot; do
|
||||
for dir in '' /boot /EFI /boot/EFI /@ /@/boot /@/boot/EFI /@/EFI; do
|
||||
if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
|
||||
syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
|
||||
elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
|
||||
syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
|
||||
elif [ -f "${dir}"/syslinux/extlinux.conf ]; then
|
||||
syslinux_configfile -s "${dir}"/syslinux/extlinux.conf
|
||||
elif [ -f "${dir}"/extlinux/extlinux.conf ]; then
|
||||
syslinux_configfile -s "${dir}"/extlinux/extlinux.conf
|
||||
fi
|
||||
done
|
||||
}
|
||||
function search_isolinux {
|
||||
echo "\nAttempting to parse isolinux/syslinux config from '${1}' devices"
|
||||
echo "\nAttempting to parse iso/sys/extlinux config from '${1}' devices"
|
||||
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
|
||||
for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
||||
try_isolinux_config "(${1}${i},${part})"
|
||||
|
@ -75,20 +81,28 @@ function search_isolinux {
|
|||
done
|
||||
echo # Insert newline
|
||||
}
|
||||
function try_bootcfg {
|
||||
try_user_config "${1}"
|
||||
try_isolinux_config "${1}"
|
||||
}
|
||||
function search_bootcfg {
|
||||
search_grub "${1}"
|
||||
search_isolinux "${1}"
|
||||
}
|
||||
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
|
||||
|
||||
if [ "${grub_scan_disk}" != "ata" ]; then
|
||||
search_grub ahci
|
||||
search_bootcfg ahci
|
||||
fi
|
||||
if [ "${grub_scan_disk}" != "ahci" ]; then
|
||||
search_grub ata
|
||||
search_bootcfg ata
|
||||
fi
|
||||
|
||||
# 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"
|
||||
lvmvol="lvm/grubcrypt-bootvol lvm/grubcrypt-rootvol"
|
||||
|
||||
raidvol="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
|
||||
|
||||
|
@ -96,7 +110,7 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o
|
|||
# TODO: optimize grub itself, and use */? here for everything
|
||||
|
||||
for vol in ${lvmvol} ${raidvol} ; do
|
||||
try_user_config "${vol}"
|
||||
try_bootcfg "${vol}"
|
||||
done
|
||||
|
||||
unset ahcidev
|
||||
|
@ -122,58 +136,35 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o
|
|||
|
||||
# after cryptomount, lvm volumes might be available
|
||||
for vol in ${lvmvol}; do
|
||||
try_user_config "${vol}"
|
||||
try_bootcfg "${vol}"
|
||||
done
|
||||
|
||||
search_grub crypto
|
||||
search_bootcfg crypto
|
||||
|
||||
if [ "${grub_scan_disk}" != "ata" ]; then
|
||||
# Last resort, if all else fails
|
||||
set root=ahci0,1
|
||||
for p in / /boot/; do
|
||||
if [ -f "${p}vmlinuz" ]; then
|
||||
linux ${p}vmlinuz root=/dev/sda1 rw
|
||||
if [ -f "${p}initrd.img" ]; then
|
||||
initrd ${p}initrd.img
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "${grub_scan_disk}" != "ahci" ]; then
|
||||
# Last resort (for setups that use IDE instead of SATA)
|
||||
set root=ata0,1
|
||||
for p in / /boot/; do
|
||||
if [ -f "${p}vmlinuz" ]; then
|
||||
linux ${p}vmlinuz root=/dev/sda1 rw
|
||||
if [ -f "${p}initrd.img" ]; then
|
||||
initrd ${p}initrd.img
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
for vol in lvm/* ; do
|
||||
try_bootcfg "${vol}"
|
||||
done
|
||||
|
||||
true # Prevent pager requiring to accept each line instead of whole screen
|
||||
}
|
||||
|
||||
menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
|
||||
search_isolinux ahci
|
||||
menuentry 'Search for GRUB/SYSLINUX/EXTLINUX/ISOLINUX on USB [s]' --hotkey='s' {
|
||||
search_bootcfg usb
|
||||
}
|
||||
menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
|
||||
search_isolinux usb
|
||||
menuentry 'Search for GRUB/SYSLINUX/EXTLINUX/ISOLINUX on AHCI [a]' --hotkey='a' {
|
||||
search_bootcfg ahci
|
||||
}
|
||||
menuentry 'Search ISOLINUX menu (ATA/IDE) [d]' --hotkey='d' {
|
||||
search_isolinux ata
|
||||
menuentry 'Search for GRUB/SYSLINUX/EXTLINUX/ISOLINUX on ATA/IDE [d]' --hotkey='d' {
|
||||
search_bootcfg ahci
|
||||
}
|
||||
if [ -f (cbfsdisk)/grubtest.cfg ]; then
|
||||
menuentry 'Load test configuration (grubtest.cfg) inside of CBFS [t]' --hotkey='t' {
|
||||
set root='(cbfsdisk)'
|
||||
if [ -f /grubtest.cfg ]; then
|
||||
configfile /grubtest.cfg
|
||||
fi
|
||||
}
|
||||
menuentry 'Search for GRUB2 configuration on external media [s]' --hotkey='s' {
|
||||
search_grub usb
|
||||
}
|
||||
fi
|
||||
if [ -f (cbfsdisk)/seabios.elf ]; then
|
||||
menuentry 'Load SeaBIOS (payload) [b]' --hotkey='b' {
|
||||
set root='cbfsdisk'
|
||||
|
|
Loading…
Reference in a new issue