删除 CentOS Stream 8 开机多余引导项及等待时间

笔者的运行环境:

  • CentOS Stream 8 x86_64

  笔者的电脑在安装 CentOS Stream 8 之后,开机一直出现 5 秒的开机引导项选择等待。在该引导项中,除了无操作之后,系统默认选择的 CentOS Stream 8,还有两个多余项:

  • CentOS (0-rescue-XXX) 8

  • System setup

  它们总是延长开机时间,因此笔者决定去掉它们。

删除 System setup

  1. 进入目录 /etc/

    [root@localhost ~]# cd /etc/
    
  2. 输入如下命令来查找与 grub 有关的文件。

    [root@localhost etc]# ls -lF *grub*
    lrwxrwxrwx. 1 root root  31 32 16:03 grub2-efi.cfg -> ../boot/efi/EFI/centos/grub.cfg*
    
    grub.d:
    总用量 92
    -rwxr-xr-x. 1 root root  8958 32 16:03 00_header*
    -rwxr-xr-x. 1 root root  1043 721 14:41 00_tuned*
    -rwxr-xr-x. 1 root root   232 32 16:03 01_users*
    -rwxr-xr-x. 1 root root   832 32 16:03 08_fallback_counting*
    -rwxr-xr-x. 1 root root 14088 32 16:03 10_linux*
    -rwxr-xr-x. 1 root root   830 32 16:03 10_reset_boot_success*
    -rwxr-xr-x. 1 root root   889 32 16:03 12_menu_auto_hide*
    -rwxr-xr-x. 1 root root 11696 32 16:03 20_linux_xen*
    -rwxr-xr-x. 1 root root  2559 32 16:03 20_ppc_terminfo*
    -rwxr-xr-x. 1 root root 10670 32 16:03 30_os-prober*
    -rwxr-xr-x. 1 root root  1412 32 16:03 30_uefi-firmware*
    -rwxr-xr-x. 1 root root   214 32 16:03 40_custom*
    -rwxr-xr-x. 1 root root   216 32 16:03 41_custom*
    -rw-r--r--. 1 root root   483 32 16:03 README
    

    在这里插入图片描述

  3. 可以看出,在上面列出的文件中,我们需要的文件为 grub2-efi.cfg。不过,这是一个符号链接文件,它指向文件 /boot/efi/EFI/centos/grub.cfg。可以选择直接编辑文件 grub2-efi.cfg,也可以选择编辑文件 grub.cfg

  4. 以文本方式打开上述文件,找到与 menuentrySystem setup 有关的段落。

    ### BEGIN /etc/grub.d/30_uefi-firmware ###
    menuentry 'System setup' $menuentry_id_option 'uefi-firmware' {
    	fwsetup
    }
    ### END /etc/grub.d/30_uefi-firmware ###
    
  5. 将此段注释或删除。(注意:修改前最好先备份,以免发生误修改)

    ### BEGIN /etc/grub.d/30_uefi-firmware ###
    # menuentry 'System setup' $menuentry_id_option 'uefi-firmware' {
    #	fwsetup
    #}
    ### END /etc/grub.d/30_uefi-firmware ###
    
  6. 现在,开机引导项 System setup 就被去掉了。重启 CentOS Stream 8 即可看到效果。

删除 CentOS (0-rescue-XXX)

  1. 与上面 删除"System setup" 类似的方法,在文件 /boot/efi/EFI/centos/grub.cfg 中寻找与 menuentryCentOS (0-rescue-XXX) 有关的段落,并注释掉。

  2. 如果没有找到(笔者在 CentOS Stream 8 上没有找到),说明上述的引导项没有位于此文件中,不过也应该位于某个目录中。于是扩大查找范围,在目录 /boot 中查找关键字 0-rescue

    (下面的 XXX 是被笔者替换过的序列号文本,不同电脑会有不同。)

    [root@localhost ~]# grep -rn "0-rescue" /boot
    /boot/loader/entries/XXX-0-rescue.conf:1:title CentOS (0-rescue-XXX) 8
    /boot/loader/entries/XXX-0-rescue.conf:2:version 0-rescue-XXX
    /boot/loader/entries/XXX-0-rescue.conf:3:linux /vmlinuz-0-rescue-XXX
    /boot/loader/entries/XXX-0-rescue.conf:4:initrd /initramfs-0-rescue-XXX.img
    /boot/loader/entries/XXX-0-rescue.conf:6:id centos-XXX-0-rescue-XXX
    /boot/System.map-4.18.0-326.el8.x86_64:9105:XXX T cgroup_rstat_exit
    /boot/System.map-4.18.0-326.el8.x86_64:26614:XXX T acpi_disable
    /boot/System.map-4.18.0-326.el8.x86_64:54743:XXX r __pci_fixup_resume_earlyricoh_mmc_fixup_XXX
    
  3. 果然查找到了关键信息。上面的输出表明,关键信息在文件 /boot/loader/entries/XXX-0-rescue.conf 中。打开目录 /boot/loader/entries/,可以发现其中有两个文件,正好对应着 CentOS Stream 8 开机的剩余两个开机引导项。

    [root@localhost ~]# ls /boot/loader/entries/
    XXX-0-rescue.conf
    XXX-4.18.0-326.el8.x86_64.conf
    
  4. 删除上述的文件 XXX-0-rescue.conf 即可。重启 CentOS Stream 8 即可看到效果。

    (注意:删除前最好先备份。不要删除另外一个、当前系统的引导项!)

去掉开机关于引导项的 5 秒等待时间

  1. 与上面 删除"System setup"类似的方法,打开文件 /boot/efi/EFI/centos/grub.cfg,找到如下段落:

    (注意:一定要选择如下段落。此文件中可能有与如下代码相似的代码,不要找错了。)

    terminal_output console
    if [ x$feature_timeout_style = xy ] ; then
      set timeout_style=menu
      set timeout=5
    # Fallback normal timeout code in case the timeout_style feature is
    # unavailable.
    else
      set timeout=5
    fi
    
  2. 将上述段落中的时间改为 0。即,将 timeout=5 改为 timeout=0

    (注意:修改前最好先备份,以免发生误修改)

    terminal_output console
    if [ x$feature_timeout_style = xy ] ; then
      set timeout_style=menu
      set timeout=0
    # Fallback normal timeout code in case the timeout_style feature is
    # unavailable.
    else
      set timeout=0
    fi
    
  3. 现在,开机引导项的等待时间就被去掉了。重启 CentOS Stream 8 即可看到效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值