Do not attempt to manually edit /etc/grub2.cfg because it is automatically created from files within the /boot/ directory tree.
To change the grub menu, edit the /etc/default/grub file that defines the general settings and the /etc/grub.d/40_custom file to add specific custom entries.
/etc/default/grub
# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
After editing, run grub2-mkconfig
# grub2-mkconfig -o /boot/grub2/grub.cfg
On UEFI-based systems, the command will be:
# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
The menu entries are in:
/boot/grub2/grub.cfg
To list all the menu entries:
# grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2
To show the default:
# grub2-editenv list
The default entry is defined by the GRUB_DEFAULT
located in: /etc/default/grub
If the GRUB_DEFAULT line is set as saved, the parameter is stored in:
/boot/grub2/grubenv
The /boot/grub2/grubenv file cannot be manually edited.
Use grub2-set-default to change the default.
# grub2-set-default 2
Reboot the system to boot to the new default.
To limit the list of Installed Kernels Permanent
Edit /etc/yum.conf
and change the entry in:
installonly_limit=5