From 5a3b0dab9668bbdc96d2bcf7e541fe0d99035b98 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 12 Jan 2025 13:19:48 +0000 Subject: [PATCH] grub.cfg: Scan *every* LVM device We were scanning a hardcoded set up LVM volumes, so in practise, LVM boot didn't really work. We did this because scanning for asterisk is slow on some machines. However, since LVM is the last one, and since most users don't boot directly from LVM, it wasn't that much of an issue in practise. Signed-off-by: Leah Rowe --- config/grub/default/config/payload | 29 ++++++++++++++--------------- config/grub/nvme/config/payload | 26 +++++++++++--------------- config/grub/xhci/config/payload | 26 +++++++++++--------------- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/config/grub/default/config/payload b/config/grub/default/config/payload index 05e64bbd..91afcc7b 100644 --- a/config/grub/default/config/payload +++ b/config/grub/default/config/payload @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-or-later -# Copyright (C) 2014-2016,2020-2021,2023-2024 Leah Rowe +# Copyright (C) 2014-2016,2020-2021,2023-2025 Leah Rowe # Copyright (C) 2015 Klemens Nanni set prefix=(memdisk)/boot/grub @@ -143,16 +143,12 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o # 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/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" - # in practise, doing multiple redundant checks is perfectly fast and + # in practise, doing multiple redundant checks is perfectly fast # TODO: optimize grub itself, and use */? here for everything - for vol in ${lvmvol} ${raidvol} ; do + for vol in ${raidvol} ; do try_bootcfg "${vol}" done @@ -164,6 +160,9 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o bootdev="${bootdev} (ahci${i},${part})" elif [ "${grub_disk}" = "ata" ]; then bootdev="${bootdev} (ata${i},${part})" + elif [ "${grub_disk}" = "nvme" ]; then + # TODO: do we care about other namesapces + bootdev="${bootdev} (nvme${i}n1,${part})" fi done done @@ -171,21 +170,21 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o set pager=0 echo -n "Attempting to unlock encrypted volumes" - for dev in ${bootdev} ${lvmvol} ${raidvol}; do + for dev in ${bootdev} ${raidvol}; do if cryptomount "${dev}" ; then break ; fi done set pager=1 echo - # after cryptomount, lvm volumes might be available - for vol in ${lvmvol}; do - try_bootcfg "${vol}" - done - search_bootcfg crypto - for vol in lvm/* ; do - try_bootcfg "${vol}" + # after cryptomount, lvm volumes might be available + # using * is slow on some machines, but we use it here, + # just once. in so doing, we find every lvm volume + for vol in (*); do + if regexp ^lvm/ $vol; then + try_bootcfg "${vol}" + fi done true # Prevent pager requiring to accept each line instead of whole screen diff --git a/config/grub/nvme/config/payload b/config/grub/nvme/config/payload index 52b8dfd9..68e6b52a 100644 --- a/config/grub/nvme/config/payload +++ b/config/grub/nvme/config/payload @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-or-later -# Copyright (C) 2014-2016,2020-2021,2023-2024 Leah Rowe +# Copyright (C) 2014-2016,2020-2021,2023-2025 Leah Rowe # Copyright (C) 2015 Klemens Nanni set prefix=(memdisk)/boot/grub @@ -155,16 +155,12 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o # 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/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" - # in practise, doing multiple redundant checks is perfectly fast and + # in practise, doing multiple redundant checks is perfectly fast # TODO: optimize grub itself, and use */? here for everything - for vol in ${lvmvol} ${raidvol} ; do + for vol in ${raidvol} ; do try_bootcfg "${vol}" done @@ -186,21 +182,21 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o set pager=0 echo -n "Attempting to unlock encrypted volumes" - for dev in ${bootdev} ${lvmvol} ${raidvol}; do + for dev in ${bootdev} ${raidvol}; do if cryptomount "${dev}" ; then break ; fi done set pager=1 echo - # after cryptomount, lvm volumes might be available - for vol in ${lvmvol}; do - try_bootcfg "${vol}" - done - search_bootcfg crypto - for vol in lvm/* ; do - try_bootcfg "${vol}" + # after cryptomount, lvm volumes might be available + # using * is slow on some machines, but we use it here, + # just once. in so doing, we find every lvm volume + for vol in (*); do + if regexp ^lvm/ $vol; then + try_bootcfg "${vol}" + fi done true # Prevent pager requiring to accept each line instead of whole screen diff --git a/config/grub/xhci/config/payload b/config/grub/xhci/config/payload index 6a0fc250..ebfd1fea 100644 --- a/config/grub/xhci/config/payload +++ b/config/grub/xhci/config/payload @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-or-later -# Copyright (C) 2014-2016,2020-2021,2023-2024 Leah Rowe +# Copyright (C) 2014-2016,2020-2021,2023-2025 Leah Rowe # Copyright (C) 2015 Klemens Nanni set prefix=(memdisk)/boot/grub @@ -156,16 +156,12 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o # 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/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" - # in practise, doing multiple redundant checks is perfectly fast and + # in practise, doing multiple redundant checks is perfectly fast # TODO: optimize grub itself, and use */? here for everything - for vol in ${lvmvol} ${raidvol} ; do + for vol in ${raidvol} ; do try_bootcfg "${vol}" done @@ -187,21 +183,21 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o set pager=0 echo -n "Attempting to unlock encrypted volumes" - for dev in ${bootdev} ${lvmvol} ${raidvol}; do + for dev in ${bootdev} ${raidvol}; do if cryptomount "${dev}" ; then break ; fi done set pager=1 echo - # after cryptomount, lvm volumes might be available - for vol in ${lvmvol}; do - try_bootcfg "${vol}" - done - search_bootcfg crypto - for vol in lvm/* ; do - try_bootcfg "${vol}" + # after cryptomount, lvm volumes might be available + # using * is slow on some machines, but we use it here, + # just once. in so doing, we find every lvm volume + for vol in (*); do + if regexp ^lvm/ $vol; then + try_bootcfg "${vol}" + fi done true # Prevent pager requiring to accept each line instead of whole screen