2024-12-13 14:58:48 +01:00
|
|
|
# shellcheck disable=SC2148 # Does not check for #!
|
2024-06-27 02:40:56 +02:00
|
|
|
# Copyright (C) 2013, 2024 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
|
2024-08-26 14:25:31 +02:00
|
|
|
# Copyright (C) 2013-2016, 2020-2021 Leah Rowe <leah@libreboot.org>
|
|
|
|
# Copyright (C) 2021 Vitali64 <vitali64pmemail@protonmail.com>
|
|
|
|
# Copyright (C) 2023 Adrien 'neox' Bourmault <neox@gnu.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2024-12-13 14:58:48 +01:00
|
|
|
# shellcheck disable=SC2121 # warn against set var=val
|
|
|
|
# shellcheck disable=SC1036 # error: invalid '('
|
|
|
|
# shellcheck disable=SC1088 # error: invalid uses of parentheses
|
2021-05-18 14:56:12 +02:00
|
|
|
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
|
2021-12-20 00:15:32 +01:00
|
|
|
terminal_input --append usb_keyboard
|
2021-05-18 14:56:12 +02:00
|
|
|
terminal_output --append cbmemc
|
|
|
|
|
|
|
|
gfxpayload=keep
|
|
|
|
terminal_output --append gfxterm
|
|
|
|
|
2021-10-31 01:54:53 +02:00
|
|
|
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
|
|
|
|
|
2021-05-18 14:56:12 +02:00
|
|
|
set default="0"
|
2021-10-30 19:23:18 +02:00
|
|
|
set timeout=10
|
2021-05-18 14:56:12 +02:00
|
|
|
set pager=1
|
2021-12-29 07:55:07 +01:00
|
|
|
set grub_scan_disk="both"
|
2021-05-18 14:56:12 +02:00
|
|
|
|
|
|
|
keymap usqwerty
|
|
|
|
function try_user_config {
|
|
|
|
set root="${1}"
|
|
|
|
for dir in boot grub grub2 boot/grub boot/grub2; do
|
2023-08-08 12:58:02 +02:00
|
|
|
for name in '' gnuboot_ osboot_ autoboot_ coreboot_; do
|
2021-05-18 14:56:12 +02:00
|
|
|
if [ -f /"${dir}"/"${name}"grub.cfg ]; then
|
2021-10-31 18:55:49 +01:00
|
|
|
unset superusers
|
2021-05-18 14:56:12 +02:00
|
|
|
configfile /"${dir}"/"${name}"grub.cfg
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
function search_grub {
|
2021-12-29 07:23:57 +01:00
|
|
|
echo -n "Attempting to load grub.cfg from '${1}' devices"
|
2021-12-28 19:23:10 +01:00
|
|
|
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_user_config "(${1}${i},${part})"
|
|
|
|
done
|
2021-12-29 07:04:42 +01:00
|
|
|
# raw devices e.g. (ahci0) instead of (ahci0,1)
|
2021-12-28 19:23:10 +01:00
|
|
|
try_user_config "(${1}${i})"
|
2021-05-18 14:56:12 +02:00
|
|
|
done
|
2021-12-29 07:23:57 +01:00
|
|
|
echo # Insert newline
|
2021-05-18 14:56:12 +02:00
|
|
|
}
|
2021-12-28 19:23:10 +01:00
|
|
|
|
2021-05-18 14:56:12 +02:00
|
|
|
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 {
|
2021-12-29 07:23:57 +01:00
|
|
|
echo "\nAttempting to parse isolinux/syslinux config from '${1}' devices"
|
2021-12-29 03:37:05 +01:00
|
|
|
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})"
|
|
|
|
done
|
2021-12-29 07:04:42 +01:00
|
|
|
# raw devices e.g. (usb0) instead of (usb0,1)
|
2021-12-29 03:37:05 +01:00
|
|
|
try_isolinux_config "(${1}${i})"
|
2021-05-18 14:56:12 +02:00
|
|
|
done
|
2021-12-29 07:23:57 +01:00
|
|
|
echo # Insert newline
|
2021-05-18 14:56:12 +02:00
|
|
|
}
|
|
|
|
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
|
2021-12-29 07:55:07 +01:00
|
|
|
|
|
|
|
if [ "${grub_scan_disk}" != "ata" ]; then
|
|
|
|
search_grub ahci
|
|
|
|
fi
|
|
|
|
if [ "${grub_scan_disk}" != "ahci" ]; then
|
|
|
|
search_grub ata
|
|
|
|
fi
|
2021-12-29 07:04:42 +01:00
|
|
|
|
2024-06-27 02:40:56 +02:00
|
|
|
for device in (*) ; do
|
resources: grub: config: fix non-working regexp.
If we do 'ls' in grub, the LVM volumes looks like that: '(lvm/[...])'
and while in certain conditions, the parenthesis are not necessary, in
the case of the code that does the regexp, it is required.
I vaguely remember having made the original tests with Trisquel 10,
and if we select LVM in Trisquel 10 both in the graphical and
netinstall installers, it ends up creating a BIOS boot partition (code
ef02), an UEFI partition (code ef00) in the case of the graphical
installer, and an LVM physical volume. I then migrated the automatic
test to Trisquel 11 before sending it.
But with the Trisquel 11 automatic test, we end up with a boot
partition, so the test will always succeed regardless of weather or
not GRUB is capable of booting from LVM partitions.
This was also tested on real hardware with Trisquel 10 installed with
the graphical installer.
The most likely explanation is that the GRUB config file being tested
also differed from the one in git, especially because both the
automatic tests and the manual tests were tested with both a
non-working GRUB configuration and a working one.
In addition using the new configuration file on a computer that was
using an old Libreboot version probably from around 2016 was made to
boot again using this new configuration file, and this looks even
more strange.
A possible explanation could be that the GRUB version is different,
though the given computer is not available for further testing, so
it's not possible to confirm that hypothesis.
Reported-by: Adrien Bourmault <neox@gnu.org>
neox: private bug report and the information on how to fix it.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Tested-by: Adrien 'neox' Bourmault <neox@gnu.org>
Acked-by: Adrien 'neox' Bourmault <neox@gnu.org>
2024-12-13 14:58:50 +01:00
|
|
|
if regexp "^\(lvm/" "${device}" ; then
|
2024-06-27 02:40:56 +02:00
|
|
|
try_user_config "${device}"
|
|
|
|
fi
|
|
|
|
done
|
2021-12-29 07:04:42 +01:00
|
|
|
|
2021-12-29 06:58:03 +01:00
|
|
|
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
|
|
|
|
|
2024-06-27 02:40:56 +02:00
|
|
|
for vol in ${raidvol} ; do
|
2021-05-18 14:56:12 +02:00
|
|
|
try_user_config "${vol}"
|
|
|
|
done
|
|
|
|
|
|
|
|
unset ahcidev
|
|
|
|
unset atadev
|
2021-12-29 06:58:03 +01:00
|
|
|
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
|
2021-12-29 07:55:07 +01:00
|
|
|
if [ "${grub_scan_disk}" != "ata" ]; then
|
|
|
|
ahcidev="(ahci${i},${part}) ${ahcidev}"
|
|
|
|
fi
|
|
|
|
if [ "${grub_scan_disk}" != "ahci" ]; then
|
|
|
|
atadev="(ata${i},${part}) ${atadev}"
|
|
|
|
fi
|
2021-10-30 17:03:10 +02:00
|
|
|
done
|
2021-12-29 06:58:03 +01:00
|
|
|
done
|
|
|
|
|
2021-05-18 14:56:12 +02:00
|
|
|
set pager=0
|
2021-12-29 07:23:57 +01:00
|
|
|
echo -n "Attempting to unlock encrypted volumes"
|
2024-06-27 02:40:56 +02:00
|
|
|
for dev in ${ahcidev} ${atadev} ${raidvol}; do
|
2021-10-30 17:03:10 +02:00
|
|
|
if cryptomount "${dev}" ; then break ; fi
|
2021-05-18 14:56:12 +02:00
|
|
|
done
|
2024-06-27 02:40:56 +02:00
|
|
|
|
|
|
|
for device in (*) ; do
|
resources: grub: config: fix non-working regexp.
If we do 'ls' in grub, the LVM volumes looks like that: '(lvm/[...])'
and while in certain conditions, the parenthesis are not necessary, in
the case of the code that does the regexp, it is required.
I vaguely remember having made the original tests with Trisquel 10,
and if we select LVM in Trisquel 10 both in the graphical and
netinstall installers, it ends up creating a BIOS boot partition (code
ef02), an UEFI partition (code ef00) in the case of the graphical
installer, and an LVM physical volume. I then migrated the automatic
test to Trisquel 11 before sending it.
But with the Trisquel 11 automatic test, we end up with a boot
partition, so the test will always succeed regardless of weather or
not GRUB is capable of booting from LVM partitions.
This was also tested on real hardware with Trisquel 10 installed with
the graphical installer.
The most likely explanation is that the GRUB config file being tested
also differed from the one in git, especially because both the
automatic tests and the manual tests were tested with both a
non-working GRUB configuration and a working one.
In addition using the new configuration file on a computer that was
using an old Libreboot version probably from around 2016 was made to
boot again using this new configuration file, and this looks even
more strange.
A possible explanation could be that the GRUB version is different,
though the given computer is not available for further testing, so
it's not possible to confirm that hypothesis.
Reported-by: Adrien Bourmault <neox@gnu.org>
neox: private bug report and the information on how to fix it.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Tested-by: Adrien 'neox' Bourmault <neox@gnu.org>
Acked-by: Adrien 'neox' Bourmault <neox@gnu.org>
2024-12-13 14:58:50 +01:00
|
|
|
if regexp "^\(lvm/" "${device}" ; then
|
2024-12-13 14:58:49 +01:00
|
|
|
if cryptomount "${device}" ; then break ; fi
|
2024-06-27 02:40:56 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2021-05-18 14:56:12 +02:00
|
|
|
set pager=1
|
2021-12-29 07:04:42 +01:00
|
|
|
echo
|
2021-05-18 14:56:12 +02:00
|
|
|
|
2021-12-29 07:04:42 +01:00
|
|
|
# after cryptomount, lvm volumes might be available
|
2024-06-27 02:40:56 +02:00
|
|
|
for device in (*) ; do
|
resources: grub: config: fix non-working regexp.
If we do 'ls' in grub, the LVM volumes looks like that: '(lvm/[...])'
and while in certain conditions, the parenthesis are not necessary, in
the case of the code that does the regexp, it is required.
I vaguely remember having made the original tests with Trisquel 10,
and if we select LVM in Trisquel 10 both in the graphical and
netinstall installers, it ends up creating a BIOS boot partition (code
ef02), an UEFI partition (code ef00) in the case of the graphical
installer, and an LVM physical volume. I then migrated the automatic
test to Trisquel 11 before sending it.
But with the Trisquel 11 automatic test, we end up with a boot
partition, so the test will always succeed regardless of weather or
not GRUB is capable of booting from LVM partitions.
This was also tested on real hardware with Trisquel 10 installed with
the graphical installer.
The most likely explanation is that the GRUB config file being tested
also differed from the one in git, especially because both the
automatic tests and the manual tests were tested with both a
non-working GRUB configuration and a working one.
In addition using the new configuration file on a computer that was
using an old Libreboot version probably from around 2016 was made to
boot again using this new configuration file, and this looks even
more strange.
A possible explanation could be that the GRUB version is different,
though the given computer is not available for further testing, so
it's not possible to confirm that hypothesis.
Reported-by: Adrien Bourmault <neox@gnu.org>
neox: private bug report and the information on how to fix it.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Tested-by: Adrien 'neox' Bourmault <neox@gnu.org>
Acked-by: Adrien 'neox' Bourmault <neox@gnu.org>
2024-12-13 14:58:50 +01:00
|
|
|
if regexp "^\(lvm/" "${device}" ; then
|
2024-06-27 02:40:56 +02:00
|
|
|
try_user_config "${device}"
|
|
|
|
fi
|
2021-05-18 14:56:12 +02:00
|
|
|
done
|
|
|
|
|
2021-10-31 19:10:34 +01:00
|
|
|
search_grub crypto
|
|
|
|
|
2021-12-29 07:55:07 +01:00
|
|
|
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
|
2021-05-18 14:56:12 +02:00
|
|
|
fi
|
2021-12-29 07:55:07 +01:00
|
|
|
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
|
2021-05-18 14:56:12 +02:00
|
|
|
fi
|
2021-12-29 07:55:07 +01:00
|
|
|
done
|
|
|
|
fi
|
2021-05-18 14:56:12 +02:00
|
|
|
|
|
|
|
true # Prevent pager requiring to accept each line instead of whole screen
|
|
|
|
}
|
2021-10-30 17:03:10 +02:00
|
|
|
|
2021-05-18 14:56:12 +02:00
|
|
|
menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
|
|
|
|
search_isolinux ahci
|
|
|
|
}
|
|
|
|
menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
|
|
|
|
search_isolinux usb
|
|
|
|
}
|
2021-12-29 07:10:45 +01:00
|
|
|
menuentry 'Search ISOLINUX menu (ATA/IDE) [d]' --hotkey='d' {
|
|
|
|
search_isolinux ata
|
|
|
|
}
|
2021-05-18 14:56:12 +02:00
|
|
|
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' {
|
2021-10-31 18:55:49 +01:00
|
|
|
set root='cbfsdisk'
|
|
|
|
chainloader /seabios.elf
|
2021-05-18 14:56:12 +02:00
|
|
|
}
|
|
|
|
fi
|
|
|
|
if [ -f (cbfsdisk)/img/grub2 ]; then
|
|
|
|
menuentry 'Return to SeaBIOS [b]' --hotkey='b' {
|
2021-10-31 18:55:49 +01:00
|
|
|
set root='cbfsdisk'
|
|
|
|
chainloader /fallback/payload
|
2021-05-18 14:56:12 +02:00
|
|
|
}
|
|
|
|
fi
|
|
|
|
menuentry 'Poweroff [p]' --hotkey='p' {
|
|
|
|
halt
|
|
|
|
}
|
|
|
|
menuentry 'Reboot [r]' --hotkey='r' {
|
|
|
|
reboot
|
|
|
|
}
|
2021-11-01 03:51:10 +01:00
|
|
|
if [ -f (cbfsdisk)/img/memtest ]; then
|
|
|
|
menuentry 'Load MemTest86+ [m]' --hotkey='m' {
|
|
|
|
set root='cbfsdisk'
|
|
|
|
chainloader /img/memtest
|
|
|
|
}
|
|
|
|
fi
|