191 lines
4.7 KiB
INI
191 lines
4.7 KiB
INI
set prefix=(memdisk)/boot/grub
|
|
|
|
insmod at_keyboard
|
|
insmod usb_keyboard
|
|
insmod nativedisk
|
|
insmod ehci
|
|
insmod ohci
|
|
insmod uhci
|
|
insmod usb
|
|
insmod usbms
|
|
insmod regexp
|
|
|
|
terminal_input --append at_keyboard
|
|
terminal_input --append usb_keyboard
|
|
terminal_output --append cbmemc
|
|
|
|
gfxpayload=keep
|
|
terminal_output --append gfxterm
|
|
|
|
if [ -f (cbfsdisk)/background.png ]; then
|
|
insmod png
|
|
background_image (cbfsdisk)/background.png
|
|
elif [ -f (cbfsdisk)/background.jpg ]; then
|
|
insmod jpeg
|
|
background_image (cbfsdisk)/background.jpg
|
|
fi
|
|
|
|
set default="0"
|
|
set timeout=10
|
|
set pager=1
|
|
|
|
keymap usqwerty
|
|
function try_user_config {
|
|
set root="${1}"
|
|
for dir in boot grub grub2 boot/grub boot/grub2; do
|
|
for name in '' osboot_ autoboot_ libreboot_ coreboot_; do
|
|
if [ -f /"${dir}"/"${name}"grub.cfg ]; then
|
|
unset superusers
|
|
configfile /"${dir}"/"${name}"grub.cfg
|
|
fi
|
|
done
|
|
done
|
|
}
|
|
function search_grub {
|
|
echo -n "Attempting to load grub.cfg from: "
|
|
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
|
|
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
|
|
echo "\nTrying partiton ${part}"
|
|
try_user_config "(${1}${i},${part})"
|
|
done
|
|
# 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
|
|
done
|
|
}
|
|
|
|
function try_isolinux_config {
|
|
set root="${1}"
|
|
for dir in '' /boot; 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
|
|
fi
|
|
done
|
|
}
|
|
function search_isolinux {
|
|
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
|
|
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
|
|
echo "\nTrying partiton ${part}"
|
|
try_isolinux_config "(${1}${i},${part})"
|
|
done
|
|
# raw devices e.g. (usb0) instead of (usb0,1)
|
|
echo "\nTrying raw usb device ..."
|
|
try_isolinux_config "(${1}${i})"
|
|
echo # Insert newline
|
|
done
|
|
|
|
}
|
|
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
|
|
search_grub ahci
|
|
search_grub ata
|
|
|
|
# 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
|
|
# TODO: optimize grub itself, and use */? here for everything
|
|
|
|
for vol in ${lvmvol} ${raidvol} ; do
|
|
try_user_config "${vol}"
|
|
done
|
|
|
|
unset ahcidev
|
|
unset atadev
|
|
for i in 11 10 9 8 7 6 5 4 3 2 1 0; do
|
|
for part in 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1; do
|
|
ahcidev="(ahci${i},${part}) ${ahcidev}"
|
|
atadev="(ata${i},${part}) ${atadev}"
|
|
done
|
|
done
|
|
|
|
set pager=0
|
|
echo -n "Attempting to cryptomount: "
|
|
for dev in ${ahcidev} ${atadev} ${lvmvol} ${raidvol}; do
|
|
echo -n "${dev} "
|
|
if cryptomount "${dev}" ; then break ; fi
|
|
done
|
|
set pager=1
|
|
echo
|
|
|
|
# after cryptomount, lvm volumes might be available
|
|
for vol in ${lvmvol}; do
|
|
try_user_config "${vol}"
|
|
done
|
|
|
|
search_grub crypto
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
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 ISOLINUX menu (USB) [u]' --hotkey='u' {
|
|
search_isolinux usb
|
|
}
|
|
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
|
|
}
|
|
if [ -f (cbfsdisk)/seabios.elf ]; then
|
|
menuentry 'Load SeaBIOS (payload) [b]' --hotkey='b' {
|
|
set root='cbfsdisk'
|
|
chainloader /seabios.elf
|
|
}
|
|
fi
|
|
if [ -f (cbfsdisk)/img/grub2 ]; then
|
|
menuentry 'Return to SeaBIOS [b]' --hotkey='b' {
|
|
set root='cbfsdisk'
|
|
chainloader /fallback/payload
|
|
}
|
|
fi
|
|
menuentry 'Poweroff [p]' --hotkey='p' {
|
|
halt
|
|
}
|
|
menuentry 'Reboot [r]' --hotkey='r' {
|
|
reboot
|
|
}
|
|
if [ -f (cbfsdisk)/img/memtest ]; then
|
|
menuentry 'Load MemTest86+ [m]' --hotkey='m' {
|
|
set root='cbfsdisk'
|
|
chainloader /img/memtest
|
|
}
|
|
fi
|