从yum安装kernel-ml
对于Centos7
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
# 查看可用的内核, lt为长期支持版, ml为主流版本
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
# 安装
yum --enablerepo=elrepo-kernel install kernel-ml
对于Centos8
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm
查看启动的内核选项(Centos8这个命令看不到什么)
$ more /etc/grub2.cfg |grep menuentry
menuentry 'CentOS Linux (5.11.13-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.el7.x86_64-advanced-9cff3d69-3769-4ad9-8460-9c54050583f9' {
menuentry 'CentOS Linux (5.4.111-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.el7.x86_64-advanced-9cff3d69-3769-4ad9-8460-9c54050583f9' {
menuentry 'CentOS Linux (3.10.0-1160.24.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.el7.x86_64-advanced-9cff3d69-3769-4ad9-8460-9c54050583f9' {
查看当前的启动项
对于Centos7
# 默认是 saved
$ more /etc/default/grub
...
GRUB_DEFAULT=saved
...
对于saved, 需要查看当前saved对应的启动项
# 查看
grub2-editenv list
# 设置为其他内核, 使用前面从grub2.cfg中得到的引号中间的内容
grub2-set-default "CentOS Linux (5.11.13-1.el7.elrepo.x86_64) 7 (Core)"
# 再次查看并确认
grub2-editenv list
对于Centos8(阿里云版本), 用这个命令看, 已经自己设置成高版本的内核了
[root@gw01 ~]# grub2-editenv list
saved_entry=20210623110808105647395700239158-5.14.0-1.el8.elrepo.x86_64
kernelopts=root=UUID=6c40ac7b-4a98-47c2-94ac-9e0a20f4a3c1 ro crashkernel=auto rhgb quiet net.ifnames=0 console=tty0 console=ttyS0,115200n8
boot_success=0
如果需要调整启动菜单等待时间, 修改完/etc/default/grub后需要更新到grub.cfg, 注意在/boot/grub2和/boot/efi/EFI/centos目录下都检查一下当前用的是哪个文件
grub2-mkconfig -o /boot/grub2/grub.cfg
清理旧内核
rpm -q kernel
-- 输出
kernel-3.10.0-957.1.3.el7.x86_64
kernel-3.10.0-957.5.1.el7.x86_64
kernel-3.10.0-957.10.1.el7.x86_64
kernel-3.10.0-957.12.1.el7.x86_64
# 将老旧内核使用yum remove命令删除
yum remove kernel-3.10.0-957.1.3.el7.x86_64 kernel-3.10.0-957.5.1.el7.x86_64 kernel-3.10.0-957.10.1.el7.x86_64