大部分以 CentOS 为例。

更新

更新内核

可以直接使用 yum update 命令:

[root@host]# yum update kernel

查询

查看系统安装了哪些内核包

Linux系统中是可以存在多个内核的,在 /boot 下面可能会有多个内核文件,但是每次启动,配置文件都会指定启动一个内核。没用的内核也可以删除。
查看安装了哪些内核可以通过 rpm -qa |grep kernel

[root@host]# rpm -qa |grep kernel kernel-tools-3.10.0-957.27.2.el7.x86_64 kernel-3.10.0-693.11.1.el7.x86_64 kernel-3.10.0-514.el7.x86_64 kernel-tools-libs-3.10.0-957.27.2.el7.x86_64

查看所有可用内核

内核启动一般在 /boot/grub2/ 下:

[root@host]# cat /boot/grub2/grub.cfg |grep menuentry if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" menuentry_id_option="" export menuentry_id_option menuentry 'CentOS Linux (3.10.0-957.27.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.el7.x86_64-advanced-b7792c31-ad03-4f04-a650-a72e861c892d' { menuentry 'CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.el7.x86_64-advanced-b7792c31-ad03-4f04-a650-a72e861c892d' { menuentry 'CentOS Linux (0-rescue-fbdeed638cd24a09bc5ea0ae945cd465) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-fbdeed638cd24a09bc5ea0ae945cd465-advanced-b7792c31-ad03-4f04-a650-a72e861c892d' {

CentOS 系统下我们可以通过下面两种方式查看:

[root@host]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (3.10.0-957.27.2.el7.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core) 2 : CentOS Linux (0-rescue-fbdeed638cd24a09bc5ea0ae945cd465) 7 (Core) [root@host]# grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2 CentOS Linux (3.10.0-957.27.2.el7.x86_64) 7 (Core) CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core) CentOS Linux (0-rescue-fbdeed638cd24a09bc5ea0ae945cd465) 7 (Core)

查看当前使用的内核

[root@host]# uname -r 3.10.0-514.el7.x86_64

修改

修改开机时默认使用的内核

通过 grub2-set-default 命令:

[root@host]# grub2-set-default 'CentOS Linux (3.10.0-957.27.2.el7.x86_64) 7 (Core)'

然后 grub2-editenv list 查看修改结果:

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

删除

删除无用内核

使用 yum removerpm -e,注意不能是当前使用的:

[root@host]# yum remove kernel-3.10.0-327.el7.x86_64

参考资料