小版本升级

1. 查看当前和可升级版本

[root@jksb_qz ~]# yum list kernel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Installed Packages
kernel.x86_64                        3.10.0-693.el7                                                                                                                                                       
kernel.x86_64                        3.10.0-1160.49.1.el7       

2. 升级

[root@jksb_qz ~]# yum update kernel -y 

3. 重启并检查

 [root@jksb_qz ~]# reboot  

 [root@jksb_qz ~]# uname -r 

大版本升级

1. 载入公钥

[root@jksb_qz ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

2. 升级安装ELRepo

[root@jksb_qz ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

3. 载入elrepo-kernel元数据

[root@jksb_qz ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel repolist

4. 查看可用的rpm包

[root@jksb_qz ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
Installed Packages
kernel.x86_64                                    3.10.0-693.el7                                                                          
kernel.x86_64                                    3.10.0-1160.49.1.el7                                                                       
kernel-devel.x86_64                              3.10.0-693.el7                                                                                                                                              
kernel-devel.x86_64                              3.10.0-1160.49.1.el7                                                                                                                                         
kernel-headers.x86_64                            3.10.0-1160.49.1.el7                                                                                                                                         
kernel-tools.x86_64                              3.10.0-1160.49.1.el7                                                                                                                                        
kernel-tools-libs.x86_64                         3.10.0-1160.49.1.el7                                                                                                                                         
Available Packages
kernel-lt.x86_64                                 5.4.168-1.el7.elrepo                                                                       
kernel-lt-devel.x86_64                           5.4.168-1.el7.elrepo                                                                                                                                         
kernel-lt-doc.noarch                             5.4.168-1.el7.elrepo                                                                                                                                         
kernel-lt-headers.x86_64                         5.4.168-1.el7.elrepo                                                                                                                                        
kernel-lt-tools.x86_64                           5.4.168-1.el7.elrepo                                                                                                                                         
kernel-lt-tools-libs.x86_64                      5.4.168-1.el7.elrepo                                                                                                                                         
kernel-lt-tools-libs-devel.x86_64                5.4.168-1.el7.elrepo                                                                                                                                        
kernel-ml.x86_64                                 5.15.11-1.el7.elrepo                                                                                                                                         
kernel-ml-devel.x86_64                           5.15.11-1.el7.elrepo                                                                                                                                        
kernel-ml-doc.noarch                             5.15.11-1.el7.elrepo                                                                                                                                         
kernel-ml-headers.x86_64                         5.15.11-1.el7.elrepo                                                                                                                                         
kernel-ml-tools.x86_64                           5.15.11-1.el7.elrepo                                                                                                                                        
kernel-ml-tools-libs.x86_64                      5.15.11-1.el7.elrepo                                                                                                                                         
kernel-ml-tools-libs-devel.x86_64                5.15.11-1.el7.elrepo  

说明:

lt :long term support,长期支持版本;

ml:mainline,主线版本;

5. 安装最新版本的kernel

[root@jksb_qz ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install  kernel-ml.x86_64  -y

6. 删除旧版本工具包

[root@jksb_qz ~]# yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64  -y

7. 安装新版本工具包

[root@jksb_qz ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install kernel-ml-tools.x86_64  -y

8. 查看内核插入顺序

[root@jksb_qz ~]# awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.15.11-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.49.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-3492312c4af1455a9be8092117be49a4) 7 (Core)

说明:默认新内核是从头插入,默认启动顺序也是从0开始(当前顺序还未生效),或者使用:

[root@jksb_qz ~]# grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2
CentOS Linux (5.15.11-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-1160.49.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-3492312c4af1455a9be8092117be49a4) 7 (Core)

其中文件 /etc/grub2.cfg 和 /boot/grub2/grub.cfg 内容一致。

9. 查看当前实际启动顺序

[root@jksb_qz ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-1160.49.1.el7.x86_64) 7 (Core)

10. 设置默认启动

[root@jksb_qz ~]# grub2-set-default 'CentOS Linux (5.15.11-1.el7.elrepo.x86_64) 7 (Core)'
[root@jksb_qz ~]# grub2-editenv list
saved_entry=CentOS Linux (5.15.11-1.el7.elrepo.x86_64) 7 (Core)

或者直接设置数值

[root@jksb_qz ~]# grub2-set-default 0  // 0代表当前第一行,也就是上面的5.15.11版本那一行内容
[root@jksb_qz ~]# grub2-editenv list
saved_entry=0

11. 重启并检查

 [root@jksb_qz ~]# reboot 

 [root@jksb_qz ~]# uname -r