文章
2023/2/16
CentOS7更新内核是否需要手动更新grub.cfg的证明
安装
先看一下当前的启动项:
[root@localhost ~]# cat /boot/grub2/grub.cfg /boot/efi/EFI/centos/grub.cfg | grep "menuentry '"menuentry 'CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-ff03f518-c736-4ae6-9246-8184ca323e79' {menuentry 'CentOS Linux (0-rescue-98762484ab64473dadd99e91d05811b6) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-98762484ab64473dadd99e91d05811b6-advanced-ff03f518-c736-4ae6-9246-8184ca323e79' {有两个
安装新内核
[root@localhost ~]# yum install ./kernel-ml-6.1.12-1.el7.elrepo.x86_64.rpm已加载插件:fastestmirror, langpacks正在检查 ./kernel-ml-6.1.12-1.el7.elrepo.x86_64.rpm: kernel-ml-6.1.12-1.el7.elrepo.x86_64./kernel-ml-6.1.12-1.el7.elrepo.x86_64.rpm 将被安装正在解决依赖关系--> 正在检查事务---> 软件包 kernel-ml.x86_64.0.6.1.12-1.el7.elrepo 将被 安装--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================================================== Package 架构 版本 源 大小==============================================================================================================================================================================================正在安装: kernel-ml x86_64 6.1.12-1.el7.elrepo /kernel-ml-6.1.12-1.el7.elrepo.x86_64 284 M
事务概要==============================================================================================================================================================================================安装 1 软件包
总计:284 M安装大小:284 MIs this ok [y/d/N]: yDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction 正在安装 : kernel-ml-6.1.12-1.el7.elrepo.x86_64 1/1grubby fatal error: unable to find a suitable template 验证中 : kernel-ml-6.1.12-1.el7.elrepo.x86_64 1/1
已安装: kernel-ml.x86_64 0:6.1.12-1.el7.elrepo
完毕![root@localhost ~]#这里出现了一个错误,无法更新grub
grubby fatal error: unable to find a suitable template所以需要 手动更新grub.cfg ,先要确定启动方式是传统引导还是uefi
ls /boot/efi/EFI如果目录存在,那么就是uefi,运行
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg如果不存在那就是传统引导
grub2-mkconfig -o /boot/grub2/grub.cfg看一下当前的启动项,已经多了一个了
[root@localhost ~]# cat /boot/grub2/grub.cfg /boot/efi/EFI/centos/grub.cfg | grep "menuentry '"cat: /boot/grub2/grub.cfg: 没有那个文件或目录menuentry 'CentOS Linux (6.1.12-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-6.1.12-1.el7.elrepo.x86_64-advanced-ff03f518-c736-4ae6-9246-8184ca323e79' {menuentry 'CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-ff03f518-c736-4ae6-9246-8184ca323e79' {menuentry 'CentOS Linux (0-rescue-98762484ab64473dadd99e91d05811b6) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-98762484ab64473dadd99e91d05811b6-advanced-ff03f518-c736-4ae6-9246-8184ca323e79' {将grub2启动项设置成第一个(新内核6.1.12-1.el7.elrepo.x86_64)然后重启
grub2-set-default 0reboot升级挂了怎么办? 卸载!
给服务器接个键盘,开机的时候选第二个启动项启动(旧内核)
卸载新内核
[root@localhost ~]# yum list installed | grep kernel-kernel-ml.x86_64 6.1.12-1.el7.elrepo installedkernel-tools.x86_64 3.10.0-693.el7 @anacondakernel-tools-libs.x86_64 3.10.0-693.el7 @anaconda刚刚安装的就是第一个,删掉
yum remove kernel-ml.x86_64按照上面 手动更新grub.cfg 后重启即可修复
如果咩咩的文章对您有帮助,您可以 请我喝牛奶