1.檢查當前內(nèi)核版本
$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
#當前的內(nèi)核版本是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 的內(nèi)核文件
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.修改內(nèi)核參數(shù)
#查找內(nèi)核參數(shù)的配置文件
$find / -name "grub.cfg"
/boot/efi/EFI/centos/grub.cfg
#查看現(xiàn)在的內(nèi)核排序
$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)
#修改內(nèi)核參數(shù)
#說明:/etc/default/grub和/boot/efi/EFI/centos/grub.cfg的區(qū)別是前者是精簡版的配置片林,后者是全量的配置腳本
#例如,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命令來重新創(chuàng)建內(nèi)核配置
$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
的區(qū)別是前者是精簡版的配置合蔽,后者是全量的配置腳本
4.重啟服務(wù)器并驗證
$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