1.查看当前系统内核版本号:
[root@localhost ~]# uname -r
3.10.0-1160.71.1.el7.x86_64
2.导入elrepo公钥:
[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
3.安装或升级elrepo:
[root@localhost ~]# yum install https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
[root@localhost ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
4.查看可用内核安装包:
[root@localhost ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
5.安装长期支持稳定版本:
[root@localhost ~]# yum --enablerepo=elrepo-kernel install -y kernel-lt
# lt = long time 长期支持内核
# ml = mainline 稳定主线版本
6.删除旧版本工具包:
[root@localhost ~]# yum remove kernel-tools-libs-3.10.0-1160.71.1.el7.x86_64 -y
7.安装新版本工具包:
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install kernel-lt-tools.x86_64 -y
8.查看内核加载顺序:
[root@localhost ~]# awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (3.10.0-1160.71.1.el7.x86_64) 7 (Core)
1 : CentOS Linux (5.4.212-1.el7.elrepo.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-360be7143c8548b780881ff416ec5603) 7 (Core)
或者通过以下方法查看:
[root@localhost ~]# grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2
CentOS Linux (3.10.0-1160.71.1.el7.x86_64) 7 (Core)
CentOS Linux (5.4.212-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (0-rescue-360be7143c8548b780881ff416ec5603) 7 (Core)
9.查看当前系统默认启动内核:
[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-1160.71.1.el7.x86_64) 7 (Core)
设置默认启动:
[root@localhost ~]# grub2-set-default 'CentOS Linux (5.4.212-1.el7.elrepo.x86_64) 7 (Core)'
再次查看默认启动内核:
[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (5.4.212-1.el7.elrepo.x86_64) 7 (Core)
或直接通过序号设置:
[root@localhost ~]# grub2-set-default 1
# 1代表第一行,即上面内核版本为5.4那行
[root@localhost ~]# grub2-editenv list
saved_entry=1
10.重启检查:
[root@localhost ~]# reboot
[root@localhost ~]# uname -r
5.4.212-1.el7.elrepo.x86_64