本文摘自:https://www.cnblogs.com/ding2016/p/10429640.html
| 系统 | 当前内核版本 | 小版本升级 | 大版本升级 |
| - | - | - | - |
| CentOS 7.6 | 3.10.0-957 | 3.10.0-957.5.1 | 4.20.12-1(目前最新) |
[root@server-1 ~]# yum list kernel
Installed Packages
kernel.x86_64 3.10.0-957.el7 @anaconda
Available Packages
kernel.x86_64 3.10.0-957.5.1.el7 updates
[root@server-1 ~]# yum update kernel -y
[root@server-1 ~]# reboot
[root@server-1 ~]# uname -r
[root@server-1 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@server-1 ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
[root@server-1 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel repolist
[root@server-1 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*
Installed Packages
kernel.x86_64 3.10.0-957.el7 @anaconda
kernel.x86_64 3.10.0-957.5.1.el7 @updates
kernel-tools.x86_64 3.10.0-957.el7 @anaconda
kernel-tools-libs.x86_64 3.10.0-957.el7 @anaconda
Available Packages
kernel-lt.x86_64 4.4.176-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 4.4.176-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 4.4.176-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 4.4.176-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 4.4.176-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 4.4.176-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 4.4.176-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 4.20.12-1.el7.elrepo elrepo-kernel // 安装目标版本
kernel-ml-devel.x86_64 4.20.12-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 4.20.12-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 4.20.12-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 4.20.12-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 4.20.12-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 4.20.12-1.el7.elrepo elrepo-kernel
说明:
[root@server-1 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install kernel-ml.x86_64 -y
[root@server-1 ~]# yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64 -y
[root@server-1 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install kernel-ml-tools.x86_64 -y
[root@server-1 ~]# awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg0 : CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-957.5.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-ca0f6fb3c5f24478abc0a2e275281d7a) 7 (Core)
说明:默认新内核是从头插入,默认启动顺序也是从0开始(当前顺序还未生效),或者使用:
[root@server-17 ~]# grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2
CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-957.5.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-ca0f6fb3c5f24478abc0a2e275281d7a) 7 (Core)
其中文件 /etc/grub2.cfg
和 /boot/grub2/grub.cfg
内容一致。
[root@server-1 ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-957.5.1.el7.x86_64) 7 (Core)
[root@server-1 ~]# grub2-set-default 'CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)'
[root@server-1 ~]# grub2-editenv list
saved_entry=CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)
或者直接设置数值
[root@server-1 ~]# grub2-set-default 0 // 0代表当前第一行,也就是上面的4.20.12版本那一行内容
[root@server-1 ~]# grub2-editenv list
saved_entry=0
[root@server-1 ~]# reboot
[root@server-1 ~]# uname -r
“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill
标 题:centos7升级内核至最新