This is very easy task,you need yum-utils package.
- Check Installed Kernels
rpm -q kernel
kernel-2.6.32-279.el6.x86_64
kernel-2.6.32-279.2.1.el6.x86_64
kernel-2.6.32-279.5.2.el6.x86_64
kernel-2.6.32-279.9.1.el6.x86_64
- Delete / Remove Old Kernels
##CentOS,Red Hat (RHEL)
yum install yum-utils
##Package-cleanup set count as how many old kernels you want left
package-cleanup --oldkernels --count=2
- Make Amount of Installed Kernels Permanent
Edit /etc/yum.conf or /etc/dnf/dnf.conf and set installonly_limit:installonly_limit=2
原文链接:https://www.f2er.com/centos/374136.html