我制作了一个 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
}
}
这里很新,而且不太明智......
您可以添加一个子菜单吗?所以每次新扫描都会添加一个新的子菜单条目?