summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-12-18 06:44:09 +0000
committerLeah Rowe <leah@libreboot.org>2023-12-18 06:44:09 +0000
commitfbb8f8b1d0b993487aa2096dbba5113b885e4fd9 (patch)
tree61a3126dea3d7ed6b6377c06a426810849befc75
parent2d6e5ca4c41021686601f7701f77c95bce0f8ced (diff)
grub.cfg: bruteforce linux/initrd if no grub.cfgbtrfsvols
this is probably not safe, and neither is the current fall back code which is being removed from master. i already finished it before testing, but after realising the above, so i'll just stash it in this branch for now. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--config/grub/config/grub.cfg118
1 files changed, 98 insertions, 20 deletions
diff --git a/config/grub/config/grub.cfg b/config/grub/config/grub.cfg
index f6b5a19..1511d52 100644
--- a/config/grub/config/grub.cfg
+++ b/config/grub/config/grub.cfg
@@ -90,6 +90,11 @@ function search_isolinux {
done
echo # Insert newline
}
+
+function try_without_config {
+
+}
+
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
if [ "${grub_scan_disk}" != "ata" ]; then
@@ -146,31 +151,104 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o
try_user_config "${vol}"
done
- 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
+ # bruteforce as a last result. figure out how to boot
+ # linux without a grub configuration file. (crypto and lvm unsupported)
+ set vmlinuz=""
+ set initrd=""
+ set devtype=""
+ set devnum=""
+ set devletter=""
+ set partnum=""
+ for t in ata ahci; do
+ set vmlinuz=""
+ set initrd=""
+ if [ "${t}" = "ata" ] && [ "${grub_scan_disk}" = "ahci" ]; then
+ continue
+ elif [ "${t}" = "ahci" ] && [ "${grub_scan_disk}" = "ata" ]; then
+ continue
+ fi
+ for dev in 0 1 2 3 4 5 6 7 8; do
+ for part in 1 2 3 4 5 6 7 8 9; do
+ set root="${t}${devnum},${partnum}"
+ set devnum="${dev}"
+ set partnum="${part}"
+ for k in /vmlinuz* @/vmlinuz*; do
+ if [ ! -f "${k}" ] || [ ! -d /boot ]; then
+ continue
+ fi
+ set vmlinuz="${k}"
+ # do not break. if furthe rentries are
+ # available, due to alphabetic sorting,
+ # the next entry is likely a newer
+ # kernel version
+ done
+ for k in /boot/vmlinuz* @/boot/vmlinuz*; do
+ if [ "${vmlinuz}" != "" ]; then
+ break
+ fi
+ set vmlinuz="${k}"
+ done
+ if [ "${vmlinuz}" = "" ]; then
+ continue
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
+ for i in /initrd* /initramfs* @/initrd* @/initramfs*; do
+ if [ ! -f "${i}" ] || [ ! -d "/boot" ]; then
+ continue
+ done
+ set initrd="${i}"
+ # ditto. do not break yet
+ done
+ for i in /boot/initrd* /boot/initramfs* @/boot/initrd* @/boot/initramfs*; do
+ if [ "${initrd}" != "" ]; then
+ break
+ fi
+ set initrd="${i}"
+ done
+ if [ "${vmlinuz}" != "" ] && [ "${initrd}" != "" ]; then
+ set devtype="${t}"
+ break
fi
+ set vmlinuz=""
+ set initrd=""
+ done
+ if [ "${vmlinuz}" != "" ] && [ "${initrd}" != "" ]; then
+ break
fi
done
+ if [ "${vmlinuz}" != "" ] && [ "${initrd}" != "" ]; then
+ break
+ fi
+ done
+
+ if [ "${vmlinuz}" = "" ] || [ "${initrd}" = "" ]; then
+ return
+ fi
+ if [ "${devnum}" = "0" ]; then
+ set devletter="a"
+ elif [ "${devnum}" = "1" ]; then
+ set devletter="b"
+ elif [ "${devnum}" = "2" ]; then
+ set devletter="c"
+ elif [ "${devnum}" = "3" ]; then
+ set devletter="d"
+ elif [ "${devnum}" = "4" ]; then
+ set devletter="e"
+ elif [ "${devnum}" = "5" ]; then
+ set devletter="f"
+ elif [ "${devnum}" = "6" ]; then
+ set devletter="g"
+ elif [ "${devnum}" = "7" ]; then
+ set devletter="h"
+ elif [ "${devnum}" = "8" ]; then
+ set devletter="i"
+ fi
+ set btrfsvol=""
+ if [ "${vmlinuz#@}" != "${vmlinuz}" ]; then
+ set btrfsvol="rootflags=subvol=@"
fi
+ set root="${devtype}${devnum},${partnum}"
+ linux ${vmlinuz} root=/dev/sd${devletter}${partnum} ${btrfsvol} rw
+ initrd ${initrd}
true # Prevent pager requiring to accept each line instead of whole screen
}