Linux CentOS7 升级内核

1. 查看内核版本


# 显示操作系统的发行版号
[root@localhost ~]# uname -r
3.10.0-1160.el7.x86_64

# 显示系统名、节点名称、操作系统的发行版号、内核版本等等
[root@localhost ~]# uname -a
Linux localhost 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

# 查看CentOS版本
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

# 查看操作系统位数
[root@localhost ~]# getconf LONG_BIT
64

2. 升级内核


# 导入ELRepo仓库的公共密钥
[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

# 安装ELRepo仓库的yum源
[root@localhost ~]# yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm -y 

# 仓库启用后,你可以使用下面的命令列出可用的内核相关包
[root@localhost ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

# 安装主线内核版本
[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-ml -y 

# 安装长期支持版本
[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-lt -y 

3. 修改默认启动内核


# 查看系统上的所有可用内核
[root@localhost ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.12.5-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-6989e04786254754941a34b5b7989ff3) 7 (Core)

# 设置默认启动内核:‘0’ 是上面命令查询出来可用内核
[root@localhost ~]# grub2-set-default 0

# 设置默认启动内核:"CentOS Linux (5.12.5-1.el7.elrepo.x86_64) 7 (Core)" 是上面命令查询出来可用内核
[root@localhost ~]# grub2-set-default "CentOS Linux (5.12.5-1.el7.elrepo.x86_64) 7 (Core)" 

# 验证是否修改成功
[root@localhost ~]# grub2-editenv list 
saved_entry=CentOS Linux (5.12.5-1.el7.elrepo.x86_64) 7 (Core)

4. 删除旧内核


4.1 使用 yum remove 删除旧内核的 RPM 包


# 查看系统中全部的内核
[root@localhost ~]# rpm -qa | grep kernel
kernel-tools-libs-3.10.0-1160.el7.x86_64
kernel-3.10.0-1160.el7.x86_64
kernel-tools-3.10.0-1160.el7.x86_64
kernel-lt-5.4.124-1.el7.elrepo.x86_64

# 删除指定的内核
[root@localhost ~]# yum remove kernel-3.10.0-1160.el7.x86_64 \
                               kernel-tools-3.10.0-1160.el7.x86_64 \
                               kernel-tools-libs-3.10.0-1160.el7.x86_64

4.2 使用 yum-utils 工具删除旧内核


在使用 yum-utils 工具删系统安装的内核时,如果系统安装的内核数量不多于 3 个,yum-utils 工具不会删除任何一个。
只有在系统安装的内核大于 3 个时,才会自动删除旧内核。

# 安装 yum-utils
[root@localhost ~]# yum install yum-utils

# 清除旧内核
[root@localhost ~]# package-cleanup --oldkernels

亲,如果您觉得文章对您有那么一小点点帮助,希望您能给点个赞,谢谢!打赏个一分钱,那我会超级开心(✿◠‿◠)

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值