linux内核离线升级

通常,CentOS 7.9 的内核版本默认为 3.10.0,由于种种原因,linux的内核版本需要升级到5.4.240,但由于生产环境不建议在线升级,下面讲述离线升级的详细步骤,亲测可用。

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

[root@localhost ~]# uname -rs
Linux 3.10.0-1160.el7.x86_64

[root@localhost ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
1 : CentOS Linux (0-rescue-44c76cd7fc4b48c19e1046e684a125af) 7 (Core)

离线升级过程

  • 第1步,安装 centos 7 最新的 5.4.240 内核
#.下载:https://mirrors.aliyun.com/elrepo/kernel/el7/x86_64/RPMS/

curl -L http://iso.sqlfans.cn/linux/kernel-lt-5.4.240-1.el7.elrepo.x86_64.rpm -o /opt/kernel-lt-5.4.240-1.el7.elrepo.x86_64.rpm
yum localinstall -y /opt/kernel-lt-5.4.240-1.el7.elrepo.x86_64.rpm
  • 第2步,安装最新的内核之后,查看 grub.cfg 确认已经有多个内核,包括原内核 1 与新安装的内核 0
[root@localhost ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux (5.4.240-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-44c76cd7fc4b48c19e1046e684a125af) 7 (Core)
  • 第3步,新内核安装后,需调整操作系统的内核启动顺序,将 GRUB_DEFAULT=saved 改为 GRUB_DEFAULT=0
sed -i 's/^GRUB_DEFAULT.*$/GRUB_DEFAULT=0/g' /etc/default/grub
cat /etc/default/grub | grep GRUB_DEFAULT
  • 第4步,执行 grub2-mkconfig 重新生成grub配置文件
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.240-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.240-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-44c76cd7fc4b48c19e1046e684a125af
Found initrd image: /boot/initramfs-0-rescue-44c76cd7fc4b48c19e1046e684a125af.img
done
  • 第5步,执行 reboot 重启系统以生效
[root@localhost ~]# reboot

[root@localhost ~]# uname -rs
Linux 5.4.240-1.el7.elrepo.x86_64
Copyright © www.sqlfans.cn 2023 All Right Reserved更新时间: 2023-04-24 16:05:08

results matching ""

    No results matching ""