[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

KernelQ_001

or use rpm to list all kernel

rpm -qa kernel

Change the number of kernel in two way

Temporary:

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

Permanent:

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

installonly_limit=3

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

package-cleanup --oldkernels --count=3

reboot

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

GRUB_DEFAULT=2

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
default=1

Change the Default Boot Kernel Temporarily on CentOS

CentOS 7:

grub2-reboot 2
reboot

CentOS 6:

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

Reference

How to change default boot kernel permanently or temporarily on CentOS

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

Add a Comment