Linux - 修改内核启动顺序及删除无用内核

Posted fuyuteng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux - 修改内核启动顺序及删除无用内核相关的知识,希望对你有一定的参考价值。

现象:
CentOS7开机启动界面显示多个内核选项

原因:
正常情况下,有两个启动项,一个是“正常启动”,另一个是“救援模式启动”(rescue)。
如果启动项多于2个,说明当前系统有旧内核未删除。原因是CentOS更新后不会自动删除旧内核。
默认以新内核启动,可以在启动选项中临时选择,也可以修改配置永久指定。

示例:修改默认启动的内核

[[email protected] ~]# uname -r   # 查看当前内核版本
3.10.0-693.5.2.el7.x86_64
[[email protected] ~]# 
[[email protected] ~]# cat /boot/grub2/grub.cfg |grep "menuentry "  # 查看所有可用内核
menuentry ‘CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-3.10.0-327.el7.x86_64-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
menuentry ‘CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-3.10.0-327.el7.x86_64-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
menuentry ‘CentOS Linux (0-rescue-8405cda22c0b421db40478edcf9c1fb2) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-0-rescue-8405cda22c0b421db40478edcf9c1fb2-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
[[email protected] ~]# 
[[email protected] ~]# grub2-set-default ‘CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)‘
[[email protected] ~]# 
[[email protected] ~]# grub2-editenv list  # 查看内核修改结果
saved_entry=CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)
[[email protected] ~]# 

 

示例:删除无用内核

[[email protected]OS-7 ~]# uname -r   # 查看当前内核版本
3.10.0-693.5.2.el7.x86_64
[[email protected] ~]# 
[[email protected] ~]# rpm -qa |grep kernel-[0-9]  # 查看全部内核包
kernel-3.10.0-693.5.2.el7.x86_64
kernel-3.10.0-327.el7.x86_64
[[email protected] ~]# 
[[email protected] ~]# yum remove kernel-3.10.0-327.el7.x86_64  # 删除指定的无用内核
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-327.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                           Arch                              Version                                      Repository                            Size
=============================================================================================================================================================
Removing:
 kernel                            x86_64                            3.10.0-327.el7                               @anaconda                            136 M

Transaction Summary
=============================================================================================================================================================
Remove  1 Package

Installed size: 136 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : kernel-3.10.0-327.el7.x86_64                                                                                                              1/1 
  Verifying  : kernel-3.10.0-327.el7.x86_64                                                                                                              1/1 

Removed:
  kernel.x86_64 0:3.10.0-327.el7                                                                                                                             

Complete!
[[email protected] ~]# 
[[email protected] ~]# rpm -qa |grep kernel-[0-9]  # 查看全部内核包
kernel-3.10.0-693.5.2.el7.x86_64
[[email protected] ~]# 
[[email protected] ~]# cat /boot/grub2/grub.cfg |grep "menuentry "
menuentry ‘CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-3.10.0-327.el7.x86_64-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
menuentry ‘CentOS Linux (0-rescue-8405cda22c0b421db40478edcf9c1fb2) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-0-rescue-8405cda22c0b421db40478edcf9c1fb2-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
[[email protected] ~]# 

 

以上是关于Linux - 修改内核启动顺序及删除无用内核的主要内容,如果未能解决你的问题,请参考以下文章

centos7 选定默认启动内核,及删除无用内核

-Linux系统启动原理及故障排除

编译安装kernel 5.1.10及删除内核

云服务器 ECS Linux CentOS 修改内核引导顺序

Linux启动顺序运行级别及开机启动

移值linux3.4.2内核之框架及初步修改