CentOS7 如何升級kernel

2020-08-12 14:21:35

1.檢視當前內核版本

[root@wfp7-ae ~]# uname -a

Linux wfp7-ae 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@wfp7-ae ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)
[root@wfp7-ae ~]#

2.啓用 ELRepo 倉庫

ELRepo 倉庫是基於社羣的用於企業級 Linux 倉庫,提供對 RedHat Enterprise (RHEL) 和 其他基於 RHEL的 Linux 發行版(CentOS、Scientific、Fedora 等)的支援。
ELRepo 聚焦於和硬體相關的軟體包,包括檔案系統驅動、顯示卡驅動、網路驅動、音效卡驅動和攝像頭驅動等。
#匯入ELRepo倉庫的公共金鑰

rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

#安裝ELRepo倉庫的yum源

rpm -Uvh  https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm #yum源

3. 檢視可用的內核相關的包

[root@wfp7-ae Desktop]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * elrepo-kernel: dfw.mirror.rackspace.com
elrepo-kernel                                                 | 2.9 kB  00:00:00     
elrepo-kernel/primary_db                                      | 1.9 MB  00:06:03     
Available Packages
kernel-lt.x86_64                          4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-devel.x86_64                    4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-doc.noarch                      4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-headers.x86_64                  4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-tools.x86_64                    4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-tools-libs.x86_64               4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-tools-libs-devel.x86_64         4.4.232-1.el7.elrepo          elrepo-kernel
kernel-ml.x86_64                          5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-devel.x86_64                    5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-doc.noarch                      5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-headers.x86_64                  5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-tools.x86_64                    5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-tools-libs.x86_64               5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-tools-libs-devel.x86_64         5.8.0-1.el7.elrepo            elrepo-kernel
perf.x86_64                               5.8.0-1.el7.elrepo            elrepo-kernel
python-perf.x86_64                        5.8.0-1.el7.elrepo            elrepo-kernel
[root@wfp7-ae Desktop]#

4.安裝內核(已最新爲例)

[root@wfp7-ae Desktop]# yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64

5.修改grub中預設的內核版本

內核升級完成後,還需要調整

5.1檢視內核啓動順序

awk -F’ ‘$1=="menuentry " {print $2}’ /etc/grub2.cfg
  通過此命令可以看到新內核順序爲0

5.2修改內核啓動順序爲0
[root@wfp7-ae Desktop]# cat /etc/default/grub                                        
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
#GRUB_DEFAULT=saved
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

5.3接着用命令來建立內核設定
[root@wfp7-ae ~]# grub2-mkconfig -o /boot/grub2/grub.cfg                             
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.8.0-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.8.0-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-4.19.91-007.ali4000.alios7.x86_64
Found initrd image: /boot/initramfs-4.19.91-007.ali4000.alios7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.18.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.18.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-0363392b5e204820ac99c5ca36fdca09
Found initrd image: /boot/initramfs-0-rescue-0363392b5e204820ac99c5ca36fdca09.img
done

6.重新啓動檢視變化

[root@wfp7-ae Desktop]# init 6

參考:https://www.cnblogs.com/zhangxingeng/p/10941781.html