CentOS7重新生成 /boot/grub2/grub.cfg
CentOS7重新生成 /boot/grub2/grub.cfg
CentOS7 is using grub2 and the generated /boot/grub2/grub.cfg
rather than the old grub.conf
format, which is why you can't find it. The new grub.cfg file is not intended for direct editing, instead you need to modify the source files that are used to generate it.
The files in question are /etc/default/grub
and the scripts in /etc/grub.d/
. In particular, if you are looking to add your own custom entries, then you will want to append a boot stanza to /etc/grub.d/40_custom
. The stanza will look something like this:
menuentry "My custom boot entry" {
set root=(hd0,1)
linux /vmlinuz-3.11-custom
initrd /initrd-plymouth.img
}
You can add the usual options to the linux
line to pass in custom options to the kernel. Once you have everything looking the way you want it to, you run:
grub2-mkconfig --output=/boot/grub2/grub.cfg
Then, if you want to alter the default boot entry, you change the GRUB_DEFAULT
option in /etc/default/grub
to point to the new stanza you added, by zero indexed position or by name (I prefer name), something like this:
GRUB_DEFAULT="My custom boot entry"
修改/etc/default/grub
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto vconsole.keymap=us rhgb quiet"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto enforcing=0 vconsole.keymap=us rhgb quiet"
添加
enforcing=0
存盘退出
执行 grub2-mkconfig --output /boot/grub2/grub.cfg
OK
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南