vlambda博客
学习文章列表

centos7 内核如何升级

需求:由于客户容器化的需要,需要将当前的操作系统升级为5.10.7的版本。


内核升级操作步骤如下:


步骤一:载入公钥、安装elrepo

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

步骤二、载入elrepo-kernel元数据

yum --disablerepo=\* --enablerepo=elrepo-kernel repolist

步骤三、查看可用rpm、并且安装

  • 查看可用安装(其中关键字 lt 是稳定版、 mt标识是最新版)

[root@taitao-k8s-hz-basic-25 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * elrepo-kernel: mirrors.neusoft.edu.cnInstalled Packageskernel.x86_64 3.10.0-1160.el7 @anacondakernel.x86_64 3.10.0-1160.11.1.el7 @updateskernel-devel.x86_64 3.10.0-1160.11.1.el7 @updateskernel-headers.x86_64 3.10.0-1160.11.1.el7 @updateskernel-ml.x86_64 5.10.7-1.el7.elrepo @elrepo-kernelkernel-ml-devel.x86_64 5.10.7-1.el7.elrepo @elrepo-kernelkernel-ml-tools.x86_64 5.10.7-1.el7.elrepo @elrepo-kernelkernel-ml-tools-libs.x86_64 5.10.7-1.el7.elrepo @elrepo-kernelAvailable Packageskernel-lt.x86_64 5.4.89-1.el7.elrepo elrepo-kernelkernel-lt-devel.x86_64 5.4.89-1.el7.elrepo elrepo-kernelkernel-lt-doc.noarch 5.4.89-1.el7.elrepo elrepo-kernelkernel-lt-headers.x86_64 5.4.89-1.el7.elrepo elrepo-kernelkernel-lt-tools.x86_64 5.4.89-1.el7.elrepo elrepo-kernelkernel-lt-tools-libs.x86_64 5.4.89-1.el7.elrepo elrepo-kernelkernel-lt-tools-libs-devel.x86_64 5.4.89-1.el7.elrepo elrepo-kernelkernel-ml-doc.noarch 5.10.7-1.el7.elrepo elrepo-kernelkernel-ml-headers.x86_64 5.10.7-1.el7.elrepo elrepo-kernelkernel-ml-tools-libs-devel.x86_64
  • 安装

yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-tools.x86_64yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64


步骤四:查看系统上的所有可用内核

[root@taitao-k8s-hz-basic-25 ~]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfgCentOS Linux (5.10.7-1.el7.elrepo.x86_64) 7 (Core)CentOS Linux (3.10.0-1160.11.1.el7.x86_64) 7 (Core)CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)CentOS Linux (0-rescue-20201228113502924739250506992733) 7 (Core)[root@maitao-k8s-hz-basic-25 ~]# vim /etc/default/grub

步骤五:设置开机从新内核启动

  • 方法1:

grub2-set-default 0
  • 方法2:

编辑配置文件 vim /etc/default/grub将GRUB_DEFAULT=saved改为GRUB_0=saved,保存退出vim。


步骤六:运行grub2-mkconfig命令来重新创建内核配置

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

步骤七、重启动、查看内核、更新

rebootuname -ryum update
升级版本[root@cainiao-k8s-hz-rancher ~]# uname -r5.10.7-1.el7.elrepo.x86_64






爱运维^_^爱分享

如果觉得文章有帮助,麻烦点个关注和转发^)^ 👇