centos7.4升級內核3.x到4.x,使用yum安裝的方式

2020-08-08 17:00:27

1、centos版本

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

2、匯入elrepo的key,然後安裝elrepo的yum源

[root@localhost ~]# rpm -import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@localhost ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
獲取http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
獲取http://elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
準備中...                          ################################# [100%]
正在升級/安裝...
   1:elrepo-release-7.0-4.el7.elrepo  ################################# [100%]
   

3、列出可升級的內核

[root@localhost ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
 
已載入外掛:fastestmirror
elrepo-kernel                                                 | 2.9 kB  00:00:00     
elrepo-kernel/primary_db                                      | 1.9 MB  00:00:09     
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
可安裝的軟體包
elrepo-release.noarch                     7.0-5.el7.elrepo              elrepo-kernel
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

4、如圖可以看出,長期維護版本lt爲4.4,最新主線穩定版ml爲5.8,我們安裝長期維護版本內核,使用如下命令:

[root@localhost ~]# yum -y --enablerepo=elrepo-kernel install kernel-lt.x86_64  kernel-lt-devel.x86_64 
已載入外掛:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * elrepo: mirrors.tuna.tsinghua.edu.cn

5、檢視內核預設啓動順序

[root@localhost ~]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
CentOS Linux (4.4.232-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-61e6672250f14dc4bb5130e77f9f621b) 7 (Core)

如上,4.4版本內核目前位置爲0,原來的3.10版本內核目前位置爲1,所以需要修改內核啓動順序爲0。在这里插入图片描述

[root@localhost ~]# vim /etc/default/grub

原本的GRUB_DEFAULT=saved改爲GRUB_0=saved

執行grub2-mkconfig命令來重新建立內核設定:

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.232-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.4.232-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-61e6672250f14dc4bb5130e77f9f621b
Found initrd image: /boot/initramfs-0-rescue-61e6672250f14dc4bb5130e77f9f621b.img
done

6、重新啓動

在这里插入图片描述
在这里插入图片描述
可以更新一下,到此內核升級完成
在这里插入图片描述