指点成金-最美分享吧

登录

centos 7 升级内核版本

佚名 举报

篇首语:本文由小编为大家整理,主要介绍了centos 7 升级内核版本相关的知识,希望对你有一定的参考价值。

0x0 背景

        由于centos 7 在某些情况下需要使用新内核支持某些应用或者修复安全补丁。

0x01 查看当前内核版本

# uname -r

3.10.0-957.el7.x86_64

# uname -a

Linux server0709 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release

CentOS Linux release 7.9.2009 (Core)

0x02 更新yum仓库

2.1、替换阿里云yum源,并升级

# rm -f /etc/yum.repos.d/*.repo

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

 # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

 # yum clean all && yum -y update

2.2、启用elrepo仓库

# yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

0x03 升级内核

3.1、安装最新版本内核

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

3.2、设置 grub2

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

3.2.1、查看系统上的所有可用内核:

# awk -F\\' '$1=="menuentry " print i++ " : " $2' /etc/grub2.cfg

0 : CentOS Linux (5.16.2-1.el7.elrepo.x86_64) 7 (Core)

1 : CentOS Linux (3.10.0-1160.53.1.el7.x86_64) 7 (Core)

2 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)

3 : CentOS Linux (0-rescue-4b8770504d944234b29a2426b5fb5759) 7 (Core)

3.2.2、设置新的内核为grub2的默认版本

服务器上存在4 个内核,我们要使用5.16.2这个版本,可以通过 grub2-set-default 0 命令或编辑 /etc/default/grub 文件来设置

方法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_OUTPUT="console"

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rhgb quiet"

GRUB_DISABLE_RECOVERY="true"

3.2.3、生成 grub 配置文件并重启

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

 # reboot

0x04验证内核版本

# uname -r

# uname -a

以上是关于centos 7 升级内核版本的主要内容,如果未能解决你的问题,请参考以下文章