grub2 配置修改
Tag grub2, 配置, on by view 2687

grub是linux系统的引导程序,grub2相对于grub有较大的改变,centos7使用的便是grub2,/boot/grub2/grub.cfg 便是grub2的引导配置,但是你修改配置文件确不应该修改该文件。/boot/grub2/grub.cfg 这个文件是用工具生成的,工具是 grub2-mkconfig 。他所对应的源文件存储在 /etc/grub.d 下面

➜  ~ ls /etc/grub.d 
00_header  01_users  20_linux_xen     30_os-prober  41_custom
00_tuned   10_linux  20_ppc_terminfo  40_custom     README

其中,40_custom 是你的配置应该添加的地方,比如我新编译了一个内核,希望添加一个新内核的启动项,我应该编辑 40_custom 入下

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "My custom boot entry" {
   set root=(hd0,1)
   linux /boot/vmlinuz-4.4.12.x86_64
   initrd /boot/initrd-4.4.12.img
}

然后执行 grub2-mkconfig --output=/boot/grub2/grub.cfg ,你会发现在新生成的 grub.cfg 文件中包含了你的引导项配置,然后重启看看就可以发现新的启动项了。

参考文献:

[1] http://superuser.com/questions/781300/searching-for-grub-configuration-file-in-centos-7