CentOS更新内核

半日闲 2020年12月17日 103次浏览

前言

本文中主要介绍下CentOS的内核升级过程

步骤

查看内核版本

使用uname -a可以查看到系统版本,如下

[root@hecs-x-medium-2-linux-20200411110030 ~]# uname -a
Linux hecs-x-medium-2-linux-20200411110030 5.10.1-1.el7.elrepo.x86_64 #1 SMP Mon Dec 14 14:16:47 EST 2020 x86_64 x86_64 x86_64 GNU/Linux

导入密钥,更新yum源

如下即可

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
yum makecaceh 

查看epel源中可用的内核版本

如下

root@a.b:/etc/yum.repos.d # yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Failed to set locale, defaulting to C
Loaded plugins: elrepo
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Available Packages
kernel-lt-devel.x86_64                                                                        4.4.242-1.el7.elrepo                                                             elrepo-kernel
kernel-lt-doc.noarch                                                                          4.4.242-1.el7.elrepo                                                             elrepo-kernel
kernel-lt-headers.x86_64                                                                      4.4.242-1.el7.elrepo                                                             elrepo-kernel
kernel-lt-tools.x86_64                                                                        4.4.242-1.el7.elrepo                                                             elrepo-kernel
kernel-lt-tools-libs.x86_64                                                                   4.4.242-1.el7.elrepo                                                             elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                                                             4.4.242-1.el7.elrepo                                                             elrepo-kernel
kernel-ml.x86_64                                                                              5.9.7-1.el7.elrepo                                                               elrepo-kernel
kernel-ml-devel.x86_64                                                                        5.9.7-1.el7.elrepo                                                               elrepo-kernel
kernel-ml-doc.noarch                                                                          5.9.7-1.el7.elrepo                                                               elrepo-kernel
kernel-ml-headers.x86_64                                                                      5.9.7-1.el7.elrepo                                                               elrepo-kernel
kernel-ml-tools.x86_64                                                                        5.9.7-1.el7.elrepo                                                               elrepo-kernel
kernel-ml-tools-libs.x86_64                                                                   5.9.7-1.el7.elrepo                                                               elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                                                             5.9.7-1.el7.elrepo                                                               elrepo-kernel
perf.x86_64                                                                                   5.9.7-1.el7.elrepo                                                               elrepo-kernel
python-perf.x86_64                                                                            5.9.7-1.el7.elrepo                                                               elrepo-kernel

安装最新内核

如下

root@a.b:/etc/yum.repos.d # yum --enablerepo=elrepo-kernel install kernel-ml
Failed to set locale, defaulting to C
Loaded plugins: elrepo
elrepo-kernel                                                                                                                                                        | 3.0 kB  00:00:00
elrepo-kernel/primary_db                                                                                                                                             | 1.8 MB  00:00:00
[elrepo]: 67 kmod packages excluded due to dependency errors
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:5.10.1-1.el7.elrepo will be installed
--> Finished Dependency Resolution

查看配置文件中的启动内核

[root@hecs-x-medium-2-linux-20200411110030 ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.10.1-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.6.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1160.6.1.el7.centos.plus.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-1062.1.1.el7.x86_64) 7 (Core)
4 : CentOS Linux (3.10.0-957.21.3.el7.x86_64) 7 (Core)
5 : CentOS Linux (3.10.0-957.5.1.el7.x86_64) 7 (Core)
6 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
7 : CentOS Linux (0-rescue-4284cfe27c5b48c38adde30f33b4bb60) 7 (Core)

设置新的启动内核

grub2-set-default 0
## 这里的0是上面查看的配置文件中的启动内核的序号

生成grub2配置文件,并重启

$ grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.18.7-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.18.7-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-862.11.6.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.11.6.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-063ec330caa04d4baae54c6902c62e54
Found initrd image: /boot/initramfs-0-rescue-063ec330caa04d4baae54c6902c62e54.img
done

$ reboot

再次查看内核版本

[root@hecs-x-medium-2-linux-20200411110030 ~]# uname -a
Linux hecs-x-medium-2-linux-20200411110030 5.10.1-1.el7.elrepo.x86_64 #1 SMP Mon Dec 14 14:16:47 EST 2020 x86_64 x86_64 x86_64 GNU/Linux

参考文档:
https://www.cnblogs.com/xzkzzz/p/9627658.html