系统及内核版本:
[root@node5 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@node5 ~]# uname -a
Linux node6 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
更新仓库:
[root@node5 yum.repos.d]# yum update
[root@node5 yum.repos.d]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
更新内核:
启用Elrepo仓库
[root@node5 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@node5 ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
查看可用系统内核包
[root@node5 ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* elrepo-kernel: hkg.mirror.rackspace.com
elrepo-kernel | 2.9 kB 00:00
elrepo-kernel/primary_db | 1.8 MB 00:01
可安装的软件包
kernel-lt.x86_64 4.4.196-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 4.4.196-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 4.4.196-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 4.4.196-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 4.4.196-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 4.4.196-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 4.4.196-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 5.3.6-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
perf.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
python-perf.x86_64 5.3.6-1.el7.elrepo elrepo-kernel
安装最新内核
[root@node5 ~]# yum --enablerepo=elrepo-kernel install kernel-ml
查看系统上可用的所有内核:
[root@node5 ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.3.6-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-ca186cba450446219a27ee86e037534b) 7 (Core)
设置默认启动选项grub(多系统启动程序),有两种方法:
通过 grub2-set-default 0 命令设置,0为上步执行结果
通过编辑文/etc/default/grub,将GRUB_DEFAULT=saved改为GRUB_DEFAULT=0
通过 gurb2-mkconfig 命令创建 grub2 的配置文件:
[root@node5 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.3.6-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.3.6-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ca186cba450446219a27ee86e037534b
Found initrd image: /boot/initramfs-0-rescue-ca186cba450446219a27ee86e037534b.img
[root@node5 ~]# reboot
[root@node5 ~]# uname -r
5.3.6-1.el7.elrepo.x86_64
可以选择删除其余旧版本内核,若系统需要降级亦可保留其他内核
删除旧版本内核可用yum remove 或者 yum-utils:
用rpm -qa | grep kernal 得到内核列表,再用yum remove 删除
[root@node5 ~]# rpm -qa | grep kernel
kernel-tools-libs-3.10.0-1062.el7.x86_64
kernel-3.10.0-514.el7.x86_64
kernel-tools-3.10.0-1062.el7.x86_64
abrt-addon-kerneloops-2.1.11-55.el7.centos.x86_64
kernel-ml-5.3.6-1.el7.elrepo.x86_64
kernel-3.10.0-1062.el7.x86_64
yum-utils 在系统安装超过三个内核时会删除旧版本内核
[root@node5 ~]# package-cleanup --oldkernels
已加载插件:fastestmirror, langpacks
No old kernels to remove
安装指定版本内核时只需在install后面加上指定版本即可。