[Linux][CentOS] Boot Kernel quantity 修改

OS Version: CentOS 7.5.1804**

Grub2 Version: grub2-2.02-0.65

This is a command record for CentOS kernel, all the command come from internet reference.

List all available kernel images added to GRUB2

grep '^menuentry' /boot/grub2/grub.cfg


or use rpm to list all kernel

rpm -qa kernel

Change the number of kernel in two way


yum install yum-utils
package-cleanup --problems (To list dependency problems in the local RPM database)
package-cleanup --leaves (To display the RPMs that are not relied upon by any other RPM)
package-cleanup --orphans (To list installed packages which are not available from currently configured repositories)
package-cleanup --dupes (To scan for duplicates in the local RPM database)

Note: If you get any duplicate RPMs in the local database, you can use the --cleandupes option to remove them.

The --oldkernels and --count options allows you to define the number of old kernels to keep.

package-cleanup --oldkernels --count=2


You can find out the default number of kernel value is 5, you can change it to the number you want.

vim /etc/yum.conf


After you change the number, you can delete old kernet and reboot your system.

package-cleanup --oldkernels --count=3


Change the Default Kernel Version Permanently on CentOS 7

You can find out the numeric value when you cat /boot/grub2/grub.cfg, the top one is 3.10.0-862.9.1 this numeric value is 0. So, if you want 3.10.0-693.2.2 become the default kernel you can do this:

vim /etc/default/grub


After you insert or change the value, you need to regenerate grub config

grub2-mkconfig -o /boot/grub2/grub.cfg

Then reboot your system and you will see the kernel you selected.

Change the Default Kernel Version Permanently on CentOS 6 or earlier

grep '^[[:space:]]*kernel' /boot/grub/grub.conf

vim /boot/grub/grub.conf

Change the Default Boot Kernel Temporarily on CentOS

CentOS 7:

grub2-reboot 2

CentOS 6:

echo "savedefault --default=2 --once" | grub --batch


How to change default boot kernel permanently or temporarily on CentOS

RHEL7: How to set the number of old kernels kept.

Add a Comment