CentOS7 如何更新内核 update Linux Kernal version

By | 2024-01-04

系统镜像:CentOS-7-x86_64-DVD-2009.iso

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# cat /proc/version
Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020

主板网卡Intel I225-V,发现系统自带的网卡驱动有BUG,严重影响使用(插上网线重启后网卡无法使用,不通电),通过更新内核后使用正常

离线更新

查找 kernel rpm 历史版本:http://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/

1.下载内核

yum update
yum install wget -y
wget https://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-5.4.265-1.el7.elrepo.x86_64.rpm

2.安装内核

rpm -ivh kernel-lt-5.4.265-1.el7.elrepo.x86_64.rpm

3.确认安装的内核版本

[root@localhost ~]# rpm -qa | grep kernel
kernel-3.10.0-1160.el7.x86_64
kernel-tools-3.10.0-1160.el7.x86_64
kernel-lt-5.4.265-1.el7.elrepo.x86_64
kernel-tools-libs-3.10.0-1160.el7.x86_64

4.更新grub配置文件

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.265-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.265-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-0dd9158f746e42f5b33e3f33f170308a
Found initrd image: /boot/initramfs-0-rescue-0dd9158f746e42f5b33e3f33f170308a.img
done

5.设置内核启动顺序

[root@localhost ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.4.265-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-0dd9158f746e42f5b33e3f33f170308a) 7 (Core)
[root@localhost ~]# grub2-set-default 0

5.验证内核版本

[root@localhost ~]# cat /proc/version
Linux version 5.4.265-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)) #1 SMP Wed Dec 20 13:57:20 EST 2023
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

在线更新

1.导入仓库源

# 1、更新yum源仓库
yum -y update
# 2、导入ELRepo仓库的公共密钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 3、安装ELRepo仓库的yum源
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
# 4、查询可用内核版本
[root@localhost ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: hkg.mirror.rackspace.com
elrepo-kernel                                                                                          | 3.0 kB  00:00:00
elrepo-kernel/primary_db                                                                               | 2.1 MB  00:00:00
Available Packages
kernel-lt-devel.x86_64                                         5.4.265-1.el7.elrepo                              elrepo-kernel
kernel-lt-doc.noarch                                           5.4.265-1.el7.elrepo                              elrepo-kernel
kernel-lt-headers.x86_64                                       5.4.265-1.el7.elrepo                              elrepo-kernel
kernel-lt-tools.x86_64                                         5.4.265-1.el7.elrepo                              elrepo-kernel
kernel-lt-tools-libs.x86_64                                    5.4.265-1.el7.elrepo                              elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                              5.4.265-1.el7.elrepo                              elrepo-kernel
kernel-ml.x86_64                                               6.6.9-1.el7.elrepo                                elrepo-kernel
kernel-ml-devel.x86_64                                         6.6.9-1.el7.elrepo                                elrepo-kernel
kernel-ml-doc.noarch                                           6.6.9-1.el7.elrepo                                elrepo-kernel
kernel-ml-headers.x86_64                                       6.6.9-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools.x86_64                                         6.6.9-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools-libs.x86_64                                    6.6.9-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                              6.6.9-1.el7.elrepo                                elrepo-kernel
perf.x86_64                                                    5.4.265-1.el7.elrepo                              elrepo-kernel
python-perf.x86_64                                             5.4.265-1.el7.elrepo                              elrepo-kernel
[root@localhost ~]#

2.选择LT/MT版本

# 不带版本号默认安装最新版
# 安装 最新版ML 版本
# yum --enablerepo=elrepo-kernel install  kernel-ml-devel kernel-ml -y
# 安装 最新版LT 版本
# yum --enablerepo=elrepo-kernel install kernel-lt-devel kernel-lt -y
# 安装 LT 版本
yum --enablerepo=elrepo-kernel install kernel-lt-devel-5.4.265-1.el7.elrepo.x86_64 kernel-lt-5.4.265-1.el7.elrepo.x86_64 -y

3.更新grub菜单

与离线方式一样

发表评论

邮箱地址不会被公开。 必填项已用*标注