导入源

# rpm -import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# 查看kernrl版本
# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * elrepo-kernel: syd.mirror.rackspace.com
Available Packages
elrepo-release.noarch                                                    7.0-5.el7.elrepo                                            elrepo-kernel
kernel-lt.x86_64                                                         4.4.241-1.el7.elrepo                                        elrepo-kernel
kernel-lt-devel.x86_64                                                   4.4.241-1.el7.elrepo                                        elrepo-kernel
kernel-lt-doc.noarch                                                     4.4.241-1.el7.elrepo                                        elrepo-kernel
kernel-lt-headers.x86_64                                                 4.4.241-1.el7.elrepo                                        elrepo-kernel
kernel-lt-tools.x86_64                                                   4.4.241-1.el7.elrepo                                        elrepo-kernel
kernel-lt-tools-libs.x86_64                                              4.4.241-1.el7.elrepo                                        elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                                        4.4.241-1.el7.elrepo                                        elrepo-kernel
kernel-ml-doc.noarch                                                     5.9.6-1.el7.elrepo                                          elrepo-kernel
kernel-ml-headers.x86_64                                                 5.9.6-1.el7.elrepo                                          elrepo-kernel
kernel-ml-tools.x86_64                                                   5.9.6-1.el7.elrepo                                          elrepo-kernel
kernel-ml-tools-libs.x86_64                                              5.9.6-1.el7.elrepo                                          elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                                        5.9.6-1.el7.elrepo                                          elrepo-kernel
perf.x86_64                                                              5.9.6-1.el7.elrepo                                          elrepo-kernel
python-perf.x86_64                                                       5.9.6-1.el7.elrepo                                          elrepo-kernel

安装内核

版本性质:主分支ml(mainline),稳定版(stable),长期维护版lt(longterm)
本文安装的是主分支ml的5.9.6

# yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64

# 查看安装好的kernel,已经安装成功
[root@qd01-stop-k8s-node004 ~]# rpm -qa|grep kernel
kernel-headers-3.10.0-957.el7.x86_64
kernel-tools-libs-3.10.0-957.el7.x86_64
kernel-ml-devel-5.9.6-1.el7.elrepo.x86_64
kernel-3.10.0-957.el7.x86_64
abrt-addon-kerneloops-2.1.11-52.el7.centos.x86_64
kernel-devel-3.10.0-957.el7.x86_64
kernel-tools-3.10.0-957.el7.x86_64
kernel-ml-5.9.6-1.el7.elrepo.x86_64
libreport-plugin-kerneloops-2.1.11-42.el7.centos.x86_64

查看并修改grub的启动顺序

主要修改了GRUB_DEFAULT=0

cat  /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="ipv6.disable=1 crashkernel=auto biosdevname=0 net.ifnames=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

生成grub重新创建内核配置并重启

# grub2-mkconfig -o /boot/grub2/grub.cfg
# reboot

重启确认内核版本

如果重启后如果发现系统一直没起来。
~恭喜你~,进入排错环节
这里通过管理网卡,查看报错如下图
记一次CentOS 7.6内核升级(5.9.6)及故障总结

CentOS 7.6 从内核 3.10.0 升级到 5.x后,重启不了,原因是 Linux 内核 4.4.x 版本之后,dracut 命令生成的 initramfs 默认不会自动加载 mpt3sas 驱动模块。因为没有对应的驱动程序,所以识别不了系统盘,从而导致内核 vmlinuz 无法加载它的 rootfs

问题解决

1、查询initramfs的驱动

# lsinitrd -k 3.10.0-957.el7.x86_64 | grep mpt[23]sas
drwxr-xr-x   2 root     root            0 Nov  2 20:22 usr/lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/scsi/mpt3sas
-rw-r--r--   1 root     root        92972 Nov  9  2018 usr/lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/scsi/mpt3sas/mpt2sas.ko.xz

# ls /usr/lib/modules/5.9.6-1.el7.elrepo.x86_64/kernel/drivers/scsi/mpt3sas/mpt3sas.ko
/usr/lib/modules/5.9.6-1.el7.elrepo.x86_64/kernel/drivers/scsi/mpt3sas/mpt3sas.ko

可以看到在3.10内核的时候是mpt2sas驱动,可以在5.x内核中看到,新版的内核已经把mpt2sas升级为mpt3sas

2、解决方法一

a、修改/etc/dracut.conf文件
sed -i '/#add_drivers+=""/aadd_drivers+="mpt3sas"' /etc/dracut.conf

b、重新生成initramfs
# cd /boot
# dracut  -f /boot/initramfs-5.9.6-1.el7.elrepo.x86_64.img 5.9.6-1.el7.elrepo.x86_64

c、检查
# lsinitrd -k 5.9.6-1.el7.elrepo.x86_64 | grep mpt[23]sas
drwxr-xr-x   2 root     root            0 Nov  9 10:27 usr/lib/modules/5.9.6-1.el7.elrepo.x86_64/kernel/drivers/scsi/mpt3sas
-rwxr--r--   1 root     root       481320 Nov  9 10:27 usr/lib/modules/5.9.6-1.el7.elrepo.x86_64/kernel/drivers/scsi/mpt3sas/mpt3sas.ko

d、重启
# reboot

3、解决方法二

强制加载驱动
# dracut --force --add-drivers mpt3sas --kver=5.9.6
# reboot