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

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

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

■ 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 (mockbuild@x86-039.build.eng.bos.redhat.com) (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 (mockbuild@kbuilder.bsys.centos.org) (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

liking

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

文章评论