CentOS 7 YUM和離線RPM包 升級 Linux 內核


一、YUM升級內核

1、更新倉庫
yum -y update
2、用 ELRepo 倉庫
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
3、查看可用的系統內核包(可以看到,只有 4.4 和 4.20 兩個版本可以使用)
[root@localhost ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * elrepo-kernel: mirrors.neusoft.edu.cn elrepo-kernel                                                                                                                                         | 2.9 kB  00:00:00 elrepo-kernel/primary_db                                                                                                                              | 1.8 MB  00:00:01 可安裝的軟件包 kernel-lt.x86_64                                                                      4.4.169-1.el7.elrepo                                                      elrepo-kernel kernel-lt-devel.x86_64                                                                4.4.169-1.el7.elrepo                                                      elrepo-kernel kernel-lt-doc.noarch                                                                  4.4.169-1.el7.elrepo                                                      elrepo-kernel kernel-lt-headers.x86_64                                                              4.4.169-1.el7.elrepo                                                      elrepo-kernel kernel-lt-tools.x86_64                                                                4.4.169-1.el7.elrepo                                                      elrepo-kernel kernel-lt-tools-libs.x86_64                                                           4.4.169-1.el7.elrepo                                                      elrepo-kernel kernel-lt-tools-libs-devel.x86_64                                                     4.4.169-1.el7.elrepo                                                      elrepo-kernel kernel-ml.x86_64                                                                      4.20.0-1.el7.elrepo                                                       elrepo-kernel kernel-ml-devel.x86_64                                                                4.20.0-1.el7.elrepo                                                       elrepo-kernel kernel-ml-doc.noarch                                                                  4.20.0-1.el7.elrepo                                                       elrepo-kernel kernel-ml-headers.x86_64                                                              4.20.0-1.el7.elrepo                                                       elrepo-kernel kernel-ml-tools.x86_64                                                                4.20.0-1.el7.elrepo                                                       elrepo-kernel kernel-ml-tools-libs.x86_64                                                           4.20.0-1.el7.elrepo                                                       elrepo-kernel kernel-ml-tools-libs-devel.x86_64                                                     4.20.0-1.el7.elrepo                                                       elrepo-kernel perf.x86_64 4.20.0-1.el7.elrepo                                                       elrepo-kernel python-perf.x86_64                                                                    4.20.0-1.el7.elrepo                                                       elrepo-kerne
4、安裝最新內核
yum --enablerepo=elrepo-kernel install kernel-ml
5.查看系統上的所有可以內核
[root@localhost ~]#  awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (4.20.0-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-957.1.3.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-87b5a0a60fc351ad00a94aa3c5b30baa) 7 (Core)
6.設置 grub2,並生成grub配置文件
[root@localhost ~]# grub2-set-default 0 [root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.20.0-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-4.20.0-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-957.1.3.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-957.1.3.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-87b5a0a60fc351ad00a94aa3c5b30baa Found initrd image: /boot/initramfs-0-rescue-87b5a0a60fc351ad00a94aa3c5b30baa.img done
7.重啟並查看當前內核
[root@localhost ~]# reboot [root@localhost ~]# uname -r 4.20.0-1.el7.elrepo.x86_64

二、離線RPM包安裝內核

1.下載RPM包

https://elrepo.org/linux/kernel/el7/x86_64/RPMS/ #選擇自己想要的版本下載對應的
[root@localhost ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-4.4.206-1.el7.elrepo.x86_64.rpm
[root@localhost ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-devel-4.4.206-1.el7.elrepo.x86_64.rpm

 2.安裝RPM包

[root@localhost ~]# yum localinstall -y kernel-lt-4.4.206-1.el7.elrepo.x86_64.rpm kernel-lt-devel-4.4.206-1.el7.elrepo.x86_64.rpm 

3.查看當前系統上的所有可用內核啟動項

非 UEFI 設備(Legacy):
[root@localhost ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (4.4.206-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-395aa029d0cca260e8304b6bf0846236) 7 (Core)
UEFI 設備(Legacy):
[root@localhost ~]#  awk -F\' '$1=="menuentry " {print i++ " : " $2}'  /boot/efi/EFI/centos/grub.cfg 
0 : CentOS Linux (4.4.205-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-e2c56988fd1743ab9d8902c5dd4d4cc1) 7 (Core)
#注意文件名稱

4.修改默認啟動項

默認啟動項由/etc/default/grub中的GRUB_DEFAULT控制。

如果GRUB_DEFAULT=saved,則該參數將存儲在/boot/grub2/grubenv中。可使用grub2-editenv list查看:

[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)

通過grub2-set-default命令修改默認啟動項。由之前的輸出可知 CentOS Linux (4.4.206-1.el7.elrepo.x86_64) 7 (Core) 的啟動序號為0

1).通過啟動序號設置4.4.205-1.el7.elrepo.x86_64為默認啟動內核

[root@localhost ~]# grub2-editenv list
saved_entry=0  #0為4.4內核啟動序號

重啟並查看內核版本

[root@localhost ~]# reboot
[root@localhost ~]# uname -r
4.4.206-1.el7.elrepo.x86_64

2).通過內核名稱設置4.4.205-1.el7.elrepo.x86_64為默認啟動內核

恢復至3.10內核

[root@localhost ~]# grep "^menuentry"  /boot/grub2/grub.cfg
[root@localhost ~]# grub2-set-default 1
[root@localhost ~]# grub2-editenv list
saved_entry=1
[root@localhost ~]# reboot
[root@localhost ~]# uname -r
3.10.0-862.el7.x86_64

通過內核名稱設置4.4.205-1.el7.elrepo.x86_64為默認啟動內核

[root@localhost ~]# grub2-set-default "CentOS Linux (4.4.206-1.el7.elrepo.x86_64) 7 (Core)"
[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (4.4.206-1.el7.elrepo.x86_64) 7 (Core)

重啟查看內核版本

[root@localhost ~]# reboot
[root@localhost ~]# uname -r
4.4.206-1.el7.elrepo.x86_64

本文yum安裝完全抄自:https://blog.csdn.net/kikajack/article/details/79396793

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM