1

I have several menuentries in my grub2 menu, some of which point to removable devices (Ventoy, Windows, etc). Is there any way to configure grub to automatically and temporarily hide (or grey out, or mark) the menuentries for which the device/partition/label they point to is unavailable?

I was unable to obtain any information regarding this, so I suppose the answer will likely be a resounding "not possible," but...

4
  • 1
    It's not about "hiding" which doesn't seem possible per se but you can generate them dynamically. Commented Jun 18, 2023 at 7:41
  • Mmmm.... This is how Ventoy generates its menu, but not sure how to do this. I should cycle through all devices/labels plugged in, but each one has its own menuentry magic. Maybe inside a big loop I can do a case/esac thing for each one. Commented Jun 18, 2023 at 13:09
  • case/esac did not work in my grub, but if/fi does. I will add an answer for completeness, but if you write yours I will vote it. Thanks!! Commented Jun 18, 2023 at 14:31

1 Answer 1

2

Using Artem suggestion about dynamic adding the entries, this is what I did (could not make case/esac work in my grub.cfg):

for dev in LIVEBOOT VTOYEFI ESP; do
  set preroot=""
  search --no-floppy --label "$dev" --set preroot
  if [ "$preroot" != "" ]; then
    if [ "y$dev" == "yLIVEBOOT" ]; then
        menuentry "Fedora KDE Live [EFI] ($dev)" $preroot $dev --class fedora --class gnu-linux --class gnu --class os {
            set root=$2
            linuxefi /images/pxeboot/vmlinuz root=live:CDLABEL=$3 rd.live.image quiet rhgb
            initrdefi /images/pxeboot/initrd.img
        }
    fi
    if [ "y$dev" == "yESP" ]; then
        menuentry "Ruindows [SSD] ($dev)" $preroot --class windows --class os {
            insmod fat
            set root=$2
            chainloader /efi/Microsoft/Boot/bootmgfw.efi
        }
    fi
    if [ "y$dev" == "yVTOYEFI" ]; then
        menuentry "Ventoy [256GB pendrive] ($dev)" $preroot --class lubuntu --class os {
            insmod fat
            set root=$2
            chainloader /EFI/BOOT/BOOTX64.EFI
        }
    fi
  fi
done

Probably the preroot variable is not really necessary and the code can be simplified, but just in case...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .