一、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