Grub script how to remove menuentries

27 Views Asked by At

I made a grub script to detect bootable disks and show them on grub menu. It is working but I want to put a rescan button and to make that first I need to remove old menuentries. How can I do?

My working code is here:

insmod part_gpt
insmod fat
insmod chain
insmod part_msdos
insmod ext2

submenu 'Bootable Disks' {
    menuentry 'Rescan Disks' --class recovery {
        scan_bootable_disks()
    }
    
    scan_bootable_disks()
    
    function scan_bootable_disks {
        for disk in 0 1 2 3 4 5 6 7 8 9 10
        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
                set device=(hd${disk},gpt${part})
                if test -e $device; then
                    if test -e "${device}/EFI/boot/grubx64.efi" ; then
                        efi_file="${device}/EFI/boot/grubx64.efi"
    
                        eval "menuentry 'EFI Bootable Disk (at $device)' --class efi {
                          set root='$device'
                          chainloader /EFI/boot/grubx64.efi
                          boot
                        }"
                    fi
                fi
                set device=(hd${disk},msdos${part})
                if test -e $device; then
                    if test -e "${device}/EFI/boot/grubx64.efi" ; then
                        efi_file="${device}/EFI/boot/grubx64.efi"
    
                        eval "menuentry 'EFI Bootable Disk (at $device)' --class efi {
                          set root='$device'
                          chainloader /EFI/boot/grubx64.efi
                          boot
                        }"
                    fi
                fi
            done
        done
    }
}
0

There are 0 best solutions below