寻找重命名 GRUB 引导条目的正确方法

Pan*_*dya 8 grub2

我正在考虑现有/默认 GRUB 引导项的命名。目前我在 GRUB 屏幕上有以下选项:

Trisquel GNU/Linux
Advanced options for Trisquel GNU/Linux
Trisquel GNU/Linux, with Linux-Libre 3.13.0-39-lowlatency (recovery mode)
Windows 7 (loader) (on /dev/sda1)
Edubuntu ISO
Run Code Online (Sandbox Code Playgroud)

其中前三个条目是 Trisquel GNU/Linux 的默认值,4条目用于 Windows 引导加载程序,5条目是在定义的自定义条目/etc/grub.d/40_custom。现在假设我想更改第 4条目的名称/文本Windows 7 (loader) (on /dev/sda1),那么这是正确的方法?

我在/boot/grub/grub.cfg. 我想改变的例子:

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-0A7072DF7072D145' {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  0A7072DF7072D145
    else
      search --no-floppy --fs-uuid --set=root 0A7072DF7072D145
    fi
    parttool ${root} hidden-
    chainloader +1
}
### END /etc/grub.d/30_os-prober ###
Run Code Online (Sandbox Code Playgroud)

那么,我可以安全地替换'Windows 7 (loader) (on /dev/sda1)'我想要的名称/文本update-grub2吗?

简而言之,我想知道如何更改 GRUB 引导项的名称?

小智 6

您可以/boot/grub/grub.cfg直接更改,但此文件会被update-grub2. 如果您的配置不经常更改,这对您来说可能是最简单的方法。

或者看看:

或者看看这个文件夹/etc/grub.d。从那里update-grub2生成/boot/grub/grub.cfg文件。


您可以通过覆盖30_os-prober脚本中的特定 menuentry 命令来更改自动生成标记 Windows 条目的方式,尤其是当您只安装了一个 Windows 时。

/etc/grub.d/30_os-prober寻找menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows ...' '用您的标签替换零件,但保持其他选项相同。

例如在我的系统上:menuentry 'My Windows 7 system' --class windows --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' { EOF

但是有一个问题:首先,这些条目中有两个30_os-prober:一个 for chain),另一个 for efi),因此您应该更改两者。其次,我猜这些更改将被覆盖,一旦对这些文件/grub 进行了更新。


另一种方法:

您可以禁用Windows的一部分30_os-prober通过注释脚本#那些menuentry ...在Windows部分的命令chain)efi)。这将删除自动生成的 windows 条目。然后从您当前的 Windows 引导项中取出/boot/grub/grub.cfg并将其复制到自定义菜单文件中/etc/grub.d/40_custom