CentOS 7 升级内核版本

查看当前内核版本

# uname -r
3.10.0-1062.18.1.el7.x86_64

启用 ELRepo 仓库

ELRepo 仓库是基于社区的用于企业级 Linux 仓库,提供对 RedHat Enterprise (RHEL) 和 其他基于 RHEL的 Linux 发行版(CentOS、Scientific、Fedora 等)的支持。
ELRepo 聚焦于和硬件相关的软件包,包括文件系统驱动、显卡驱动、网络驱动、声卡驱动和摄像头驱动等。

#导入ELRepo仓库的公共密钥
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#安装ELRepo仓库的yum源
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

更新yum仓库

# yum update -y

查看可用的系统内核包

# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

Loaded plugins: fastestmirror, langpacks
Repository cr is listed more than once in the configuration
Repository fasttrack is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
elrepo-kernel                                                                                   | 2.9 kB  00:00:00     
elrepo-kernel/primary_db                                                                        | 1.9 MB  00:00:00     
Available Packages
elrepo-release.noarch                                      7.0-5.el7.elrepo                               elrepo-kernel
kernel-lt.x86_64                                           4.4.234-1.el7.elrepo                           elrepo-kernel
kernel-lt-devel.x86_64                                     4.4.234-1.el7.elrepo                           elrepo-kernel
kernel-lt-doc.noarch                                       4.4.234-1.el7.elrepo                           elrepo-kernel
kernel-lt-headers.x86_64                                   4.4.234-1.el7.elrepo                           elrepo-kernel
kernel-lt-tools.x86_64                                     4.4.234-1.el7.elrepo                           elrepo-kernel
kernel-lt-tools-libs.x86_64                                4.4.234-1.el7.elrepo                           elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                          4.4.234-1.el7.elrepo                           elrepo-kernel
kernel-ml.x86_64                                           5.8.5-1.el7.elrepo                             elrepo-kernel
kernel-ml-devel.x86_64                                     5.8.5-1.el7.elrepo                             elrepo-kernel
kernel-ml-doc.noarch                                       5.8.5-1.el7.elrepo                             elrepo-kernel
kernel-ml-headers.x86_64                                   5.8.5-1.el7.elrepo                             elrepo-kernel
kernel-ml-tools.x86_64                                     5.8.5-1.el7.elrepo                             elrepo-kernel
kernel-ml-tools-libs.x86_64                                5.8.5-1.el7.elrepo                             elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                          5.8.5-1.el7.elrepo                             elrepo-kernel
perf.x86_64                                                5.8.5-1.el7.elrepo                             elrepo-kernel
python-perf.x86_64                                         5.8.5-1.el7.elrepo                             elrepo-kernel

安装最新内核版本

# yum --enablerepo=elrepo-kernel install -y kernel-ml

设置 grub2

内核安装好后,需要设置为默认启动选项并重启后才会生效

  • 查看系统上的所有可用内核:
# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.8.5-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1127.18.2.el7.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-1127.13.1.el7.x86_64) 7 (Core)
4 : CentOS Linux (3.10.0-1062.18.1.el7.x86_64) 7 (Core)
5 : CentOS Linux (3.10.0-1062.9.1.el7.x86_64) 7 (Core)
6 : CentOS Linux (0-rescue-0ea734564f9a4e2881b866b82d679dfc) 7 (Core)
  • 设置新的内核为grub2的默认版本
  • 方法1、通过 grub2-set-default 0 命令设置,其中 0 是上面查询出来的可用内核
# grub2-set-default 0
  • 方法2、编辑 /etc/default/grub 文件,设置 GRUB_DEFAULT=0,通过上面查询显示的编号为 0 的内核作为默认内核:
  • 法一不成功时,可用法二
# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_TERMINAL_OUTPUT="serial console"
GRUB_CMDLINE_LINUX="crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable"
GRUB_DISABLE_RECOVERY="true"
GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"
  • 生成 grub 配置文件并重启
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.8.5-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.8.5-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.19.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.19.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.18.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.18.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.13.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.13.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.18.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.18.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.9.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.9.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-0ea734564f9a4e2881b866b82d679dfc
Found initrd image: /boot/initramfs-0-rescue-0ea734564f9a4e2881b866b82d679dfc.img
done
  • 重启系统
# reboot

验证是否升级成功

# uname -r
5.8.5-1.el7.elrepo.x86_64

删除旧内核(可选)

  • 查看系统中全部的内核:
# rpm -qa | grep kernel
kernel-tools-3.10.0-1127.19.1.el7.x86_64
kernel-ml-5.8.5-1.el7.elrepo.x86_64
kernel-3.10.0-1127.13.1.el7.x86_64
abrt-addon-kerneloops-2.1.11-57.el7.centos.x86_64
kernel-3.10.0-1062.18.1.el7.x86_64
kernel-tools-libs-3.10.0-1127.19.1.el7.x86_64
kernel-headers-3.10.0-1127.19.1.el7.x86_64
kernel-devel-3.10.0-1127.19.1.el7.x86_64
kernel-3.10.0-1062.9.1.el7.x86_64
kernel-devel-3.10.0-1062.9.1.el7.x86_64
kernel-3.10.0-1127.18.2.el7.x86_64
kernel-devel-3.10.0-1127.13.1.el7.x86_64
kernel-devel-3.10.0-1062.18.1.el7.x86_64
kernel-devel-3.10.0-1127.18.2.el7.x86_64
kernel-3.10.0-1127.19.1.el7.x86_64
  • yum remove 删除旧内核的 RPM 包,注意不要删除到最新的内核
# yum remove kernel-tools-3.10.0-1127.19.1.el7.x86_64 \
kernel-3.10.0-1127.13.1.el7.x86_64 \
abrt-addon-kerneloops-2.1.11-57.el7.centos.x86_64 \
kernel-3.10.0-1062.18.1.el7.x86_64 \
kernel-tools-libs-3.10.0-1127.19.1.el7.x86_64 \
kernel-headers-3.10.0-1127.19.1.el7.x86_64 \
kernel-devel-3.10.0-1127.19.1.el7.x86_64 \
kernel-3.10.0-1062.9.1.el7.x86_64 \
kernel-devel-3.10.0-1062.9.1.el7.x86_64 \
kernel-3.10.0-1127.18.2.el7.x86_64 \
kernel-devel-3.10.0-1127.13.1.el7.x86_64 \
kernel-devel-3.10.0-1062.18.1.el7.x86_64 \
kernel-devel-3.10.0-1127.18.2.el7.x86_64 \
kernel-3.10.0-1127.19.1.el7.x86_64


标题:CentOS 7 升级内核版本
作者:Mune
地址:https://cnxiaobai.com/articles/2021/05/18/1621336187293.html

    评论
    0 评论
avatar

取消