愿你出走半生,归来仍是少年

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. linux
  3. 正文

linux内核离线升级步骤详解【亲测可用】

2022年9月30日 2946点热度 0人点赞 0条评论

由于种种原因,linux的内核版本需要升级,但由于生产原因往往不能在线升级,在此记录笔者本人昨晚的的离线升级步骤,亲测可用。
我们知道,红帽和CentOS同源同宗,内核升级步骤也是一样的。

Table of Contents

Toggle
  • ■ Red Hat / CentOS 7最新内核下载
  • ■ 内核安装
  • ■ 此时查看所有的内核
  • ■ 内核配置
  • ■ 重新生成grub配置文件
  • ■ 然后重启系统生效
  • ■ 在 Red Hat 7.3 测试内核升级
  • ■ 在 CentOS 7.6 测试内核升级

■ Red Hat / CentOS 7最新内核下载

内核版本 5.4.214 于 2022-9-18 发布,lt 是指长期支持版本 long term

wget https://mirrors.aliyun.com/elrepo/kernel/el7/x86_64/RPMS/kernel-lt-5.4.214-1.el7.elrepo.x86_64.rpm --no-check-certificate

在以上地址可以下载各个版本的内核,再次向阿里云、网易、163、清华等这些开源镜像提供者致敬,不愧大家风范,方便了国内用户对开源软件的使用。

■ 内核安装

yum localinstall kernel-lt-5.4.214-1.el7.elrepo.x86_64.rpm
可能有包依赖关系,视情况配置yum源,或下载指定包

■ 此时查看所有的内核

awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
---【Red Hat】输出类似如下:
0 : Red Hat Enterprise Linux Server (5.4.214-1.el7.elrepo.x86_64) 7.3 (Maipo)
1 : Red Hat Enterprise Linux Server (3.10.0-514.el7.x86_64) 7.3 (Maipo)
2 : Red Hat Enterprise Linux Server (0-rescue-13fa607805964427bb4a2297f3619e6e) 7.3 (Maipo)
---【CentOS】输出类似如下:
0 : CentOS Linux (5.4.214-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.15.2.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-6d425900e59b4ef18c98680ce9a348dd) 7 (Core)

可见已有多个内核,包括原内核 1 与新安装的内核 0

■ 内核配置

新内核安装后,需修改os已有的内核启动顺序,默认启动的顺序应该为1,升级以后内核是往前面插入为0,则需设置GRUB_DEFAULT=0。
默认的配置文件 /etc/default/grub ,参数 GRUB_DEFAULT=saved

vim /etc/default/grub
GRUB_DEFAULT=saved
需改为:
GRUB_DEFAULT=0

■ 重新生成grub配置文件

grub2-mkconfig -o /boot/grub2/grub.cfg
---输出类似如下:
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.214-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.214-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-13fa607805964427bb4a2297f3619e6e
Found initrd image: /boot/initramfs-0-rescue-13fa607805964427bb4a2297f3619e6e.img
done

■ 然后重启系统生效

reboot

■ 在 Red Hat 7.3 测试内核升级

[root@node5 ~]# cat /etc/*release
Red Hat Enterprise Linux Server release 7.3 (Maipo)

【升级前】

[root@node5 ~]# uname -a
Linux node5 3.10.0-514.el7.x86_64 #1 SMP Wed Oct 19 11:24:13 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@node5 ~]# cat /proc/version
Linux version 3.10.0-514.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Wed Oct 19 11:24:13 EDT 2016
[root@node5 ~]# uname -rs
Linux 3.10.0-514.el7.x86_64

【升级后】

[root@node5 ~]# uname -a
Linux node5 5.4.214-1.el7.elrepo.x86_64 #1 SMP Sat Sep 17 11:09:50 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@node5 ~]# cat /proc/version
Linux version 5.4.214-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)) #1 SMP Sat Sep 17 11:09:50 EDT 2022
[root@node5 ~]# uname -rs
Linux 5.4.214-1.el7.elrepo.x86_64

■ 在 CentOS 7.6 测试内核升级

[root@node3:0 ~]# cat /etc/*release
CentOS Linux release 7.6.1810 (Core)

【升级前】

[root@node3:0 ~]# uname -a
Linux node3 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@node3:0 ~]# cat /proc/version
Linux version 3.10.0-1160.15.2.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Wed Feb 3 15:06:38 UTC 2021
[root@node3:0 ~]# uname -rs
Linux 3.10.0-1160.15.2.el7.x86_64

【升级后】

[root@node3:0 ~]# uname -a
Linux node3 5.4.214-1.el7.elrepo.x86_64 #1 SMP Sat Sep 17 11:09:50 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@node3:0 ~]# cat /proc/version
Linux version 5.4.214-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)) #1 SMP Sat Sep 17 11:09:50 EDT 2022
[root@node3:0 ~]# uname -rs
Linux 5.4.214-1.el7.elrepo.x86_64
标签: 暂无
最后更新:2022年9月30日

liking

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 6 月
  • 2026 年 3 月
  • 2026 年 2 月
  • 2025 年 12 月
  • 2025 年 11 月
  • 2025 年 4 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 10 月
  • 2024 年 7 月
  • 2024 年 5 月
  • 2024 年 4 月
  • 2023 年 11 月
  • 2023 年 10 月
  • 2023 年 8 月
  • 2023 年 7 月
  • 2023 年 5 月
  • 2023 年 3 月
  • 2023 年 2 月
  • 2022 年 12 月
  • 2022 年 11 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2022 年 6 月
  • 2022 年 5 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2022 年 1 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 5 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 8 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 4 月
  • 2019 年 2 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 8 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2018 年 1 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 8 月
  • 2017 年 6 月
  • 2017 年 5 月
  • 2017 年 3 月
  • 2016 年 9 月
  • 2016 年 8 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 5 月
  • 2015 年 10 月
  • 2014 年 10 月
  • 2014 年 8 月
  • 2014 年 3 月
  • 2013 年 12 月
  • 2013 年 8 月
  • 2013 年 7 月
  • 2013 年 6 月
  • 2013 年 4 月
  • 2012 年 11 月
  • 2012 年 7 月
  • 2012 年 6 月
  • 2012 年 5 月
  • 2012 年 2 月
  • 2011 年 10 月
  • 2011 年 8 月
  • 2011 年 3 月
  • 2010 年 11 月
  • 2010 年 10 月
  • 2010 年 9 月
  • 2010 年 8 月
  • 2010 年 7 月
  • 2010 年 5 月
  • 2010 年 4 月
  • 2010 年 1 月
  • 2009 年 11 月
  • 2009 年 8 月
  • 2009 年 5 月
  • 2009 年 3 月
  • 2009 年 2 月
  • 2008 年 11 月
  • 2008 年 10 月
  • 2008 年 8 月
  • 2008 年 4 月
  • 2007 年 4 月

分类

  • BigData
  • kubernetes
  • linux
  • MongoDB
  • MySQL
  • Oracle
  • PostgreSQL
  • 备份恢复
  • 安装配置
  • 性能优化
  • 技术杂谈
  • 未分类
  • 梦回红楼
  • 测试
  • 生活点滴
  • 网站建设
  • 自制工具
  • 轻松一刻
  • 运维知识
  • 问题处理

COPYRIGHT © 2026 愿你出走半生,归来仍是少年. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang