centos7升級核心到高版本
阿新 • • 發佈:2021-06-23
1、檢視當前核心版本
uname -r
3.10.0-1160.25.1.el7.x86_64
uname -a
Linux localhost.localdomain 3.10.0-1160.25.1.el7.x86_64 #1 SMP Wed Apr 28 21:49:45 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
2、更新yum倉庫
2.1、替換阿里雲yum源,並升級
rm /etc/yum.repos.d/*.repo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum clean all && yum -y update
2.2、啟用elrepo倉庫
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
3、升級核心
3.1、安裝最新版本核心
yum --enablerepo=elrepo-kernel install kernel-ml
3.2、設定 grub2
核心安裝好後,需要設定為預設啟動選項並重啟後才會生效
3.2.1、檢視系統上的所有可用核心:
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (5.12.1-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-16ba4d58b7b74338bfd60f5ddb0c8483) 7 (Core)
3.2.2、設定新的核心為grub2的預設版本
伺服器上存在4 個核心,我們要使用 5.12.1這個版本,可以通過 grub2-set-default 0 命令或編輯 /etc/default/grub 檔案來設定
方法1、通過 grub2-set-default 0 命令設定
其中 0 是上面查詢出來的可用核心
grub2-set-default 0
方法2、編輯 /etc/default/grub 檔案
設定 GRUB_DEFAULT=0,通過上面查詢顯示的編號為 0 的核心作為預設核心:
vim /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 rd.lvm.lv=cl/root rhgb quiet" GRUB_DISABLE_RECOVERY="true"
3.2.3、生成 grub 配置檔案並重啟
grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.12.1-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.12.1-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.25.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.25.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/i