1.检查当前内核版本
$uname -a
Linux agent1 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
#当前的内核版本是3.10.0
$uname -r
3.10.0-957.el7.x86_64
#查看os版本
$cat /etc/os-release
NAME="openEuler"
VERSION="20.03 (LTS)"
ID="openEuler"
VERSION_ID="20.03"
PRETTY_NAME="openEuler 20.03 (LTS)"
ANSI_COLOR="0;31"
2.下载并安装目标版本 5.4 的内核文件
linux-5.4下载地址,下载rpm包kernel-lt-5.4.xxx.el7.elrepo.x86_64.rpm
和 kernel-lt-devel-xxx.el7.elrepo.x86_64.rpm
$mdkir /home/software
#把上述rpm上传到/home/software
$cd /home/software
$rpm -ivh *
3.修改内核参数
#查找内核参数的配置文件
$find / -name "grub.cfg"
/boot/efi/EFI/centos/grub.cfg
#查看现在的内核排序
$awk -F\' '$1=="menuentry " {print $2}' /boot/efi/EFI/centos/grub.cfg
CentOS Linux (5.4.258-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-13f0acb4a7974dc29885507c2d019ae9) 7 (Core)
#修改内核参数
#说明:/etc/default/grub和/boot/efi/EFI/centos/grub.cfg的区别是前者是精简版的配置,后者是全量的配置脚本
#例如,GRUB_DEFAULT=saved修改为GRUB_DEFAULT=0
$vi /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 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
#grub2-mkconfig命令来重新创建内核配置
$grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.258-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.258-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-13f0acb4a7974dc29885507c2d019ae9
Found initrd image: /boot/initramfs-0-rescue-13f0acb4a7974dc29885507c2d019ae9.img
done
说明:/etc/default/grub
和 /boot/efi/EFI/centos/grub.cfg
的区别是前者是精简版的配置,后者是全量的配置脚本
4.重启服务器并验证
$init 6
$uname -a
Linux server1 5.4.258-1.el7.elrepo.x86_64 #1 SMP Tue Oct 10 22:42:49 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux