Centos7 内核升级完整流程

0. 准备工作

因为新装的一台 centos7 vm 作为样板机后面安装 kubernetes, 所以打算把内核版本升级,同时做一下记录,下面正式开始。
确认系统版本

# uname -a

> Linux base 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

更新系统版本并重启

 yum -y update && reboot -h now

再次查看系统版本

# uname -r

> Linux base 3.10.0-1160.36.2.el7.x86_64 #1 SMP Wed Jul 21 11:57:15 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

1. 启用EL Repo

centos发行版本使用yum只能升级至内核仓库的最新版本,centos7 目前只有升级至3.10,若要升级至最新的版本则需要添加el repo仓库, 详情请移至el repo官网
centos7执行如下:

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

查看内核可用版本

#  yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
[root@base ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
elrepo-kernel                                                                                                                             | 3.0 kB  00:00:00     
elrepo-kernel/primary_db                                                                                                                  | 2.0 MB  00:00:06     
Available Packages
kernel-lt.x86_64                                                                5.4.142-1.el7.elrepo                                                elrepo-kernel
kernel-lt-devel.x86_64                                                          5.4.142-1.el7.elrepo                                                elrepo-kernel
kernel-lt-doc.noarch                                                            5.4.142-1.el7.elrepo                                                elrepo-kernel
kernel-lt-headers.x86_64                                                        5.4.142-1.el7.elrepo                                                elrepo-kernel
kernel-lt-tools.x86_64                                                          5.4.142-1.el7.elrepo                                                elrepo-kernel
kernel-lt-tools-libs.x86_64                                                     5.4.142-1.el7.elrepo                                                elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                                               5.4.142-1.el7.elrepo                                                elrepo-kernel
kernel-ml.x86_64                                                                5.13.12-1.el7.elrepo                                                elrepo-kernel
kernel-ml-devel.x86_64                                                          5.13.12-1.el7.elrepo                                                elrepo-kernel
kernel-ml-doc.noarch                                                            5.13.12-1.el7.elrepo                                                elrepo-kernel
kernel-ml-headers.x86_64                                                        5.13.12-1.el7.elrepo                                                elrepo-kernel
kernel-ml-tools.x86_64                                                          5.13.12-1.el7.elrepo                                                elrepo-kernel
kernel-ml-tools-libs.x86_64                                                     5.13.12-1.el7.elrepo                                                elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                                               5.13.12-1.el7.elrepo                                                elrepo-kernel

注:版本选择

  • lt:长期支持版本,稳定可靠,推荐安装。
  • ml:最新主线版本,比较激进,慎重选择,不推荐安装。

安装长期支持版本

# 只安装内核使用
# yum -y --enablerepo=elrepo-kernel install kernel-lt
# 安装内核所有模块使用
# yum -y --enablerepo=elrepo-kernel install kernel-lt-*

设置GRUB默认的内核版本并重建内核配置

# sed -i s#GRUB_DEFAULT=.*#GRUB_DEFAULT=0#g /etc/default/grub
# grub2-mkconfig -o /boot/grub2/grub.cfg
# reboot -h now
[root@base ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.142-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.142-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.36.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.36.2.el7.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-f9b10b00145443b99b28522cb47d25ca
Found initrd image: /boot/initramfs-0-rescue-f9b10b00145443b99b28522cb47d25ca.img
done

查看系统版本信息

# uname -r

> Linux base 5.4.142-1.el7.elrepo.x86_64 #1 SMP Tue Aug 17 10:26:10 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux

2. 删除旧的内核版本(可选)

查看内核版本列表

# cat /boot/grub2/grub.cfg | grep 'menuentry ' | awk -F \' '{ print i++ ": " $2}'
[root@base ~]# cat /boot/grub2/grub.cfg | grep 'menuentry ' | awk -F \' '{ print i++ ": " $2}'
0: CentOS Linux (5.4.142-1.el7.elrepo.x86_64) 7 (Core)
1: CentOS Linux (3.10.0-1160.36.2.el7.x86_64) 7 (Core)
2: CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
3: CentOS Linux (0-rescue-f9b10b00145443b99b28522cb47d25ca) 7 (Core)

设置默认的启动项

# grub2-set-default 0

删除旧的内核版本

# yum -y remove $(rpm -qa | grep kernel | grep -v kernel-lt)

你可能感兴趣的:(Centos7 内核升级完整流程)