Grub 脚本如何删除菜单项

Grub 脚本如何删除菜单项

我编写了一个 grub 脚本来检测可启动磁盘并将它们显示在 grub 菜单上。它正在运行,但我想添加一个重新扫描按钮,为此,我首先需要删除旧的菜单项。我该怎么办?

我的工作代码在这里:

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
    }
}

相关内容