Cleaning up /boot/grub2/grub.cfg kernel entries on RHEL 7

desertdenizen

New Member
Joined
Feb 23, 2022
Messages
7
Reaction score
2
Credits
79
Good morning, all. I have a task to clean up all the extraneous kernel entries in my /boot/grub2/grub.cfg file. What is the easiest way to do this?
 


Remove all the kernel versions by uninstalling the associated package you want removed from there and grub.cfg will automatically be updated.
 
Thank you. That rid me of two of the eight menuentry entries in /boot/grub2/grub.cfg. How do I get rid of five of the remaining six?
 
Can you share the output of the following?
Code:
rpm -qa | grep ^kernel
cat /boot/grub2/grub.cfg
 
Can you share the output of the following?
Code:
rpm -qa | grep ^kernel
cat /boot/grub2/grub.cfg
kernel-tools-libs-3.10.0-1160.53.1.el7.x86_64
kernel-3.10.0-1160.53.1.el7.x86_64
kernel-headers-3.10.0-1160.53.1.el7.x86_64
kernel-devel-3.10.0-1160.53.1.el7.x86_64
kernel-tools-3.10.0-1160.53.1.el7.x86_64
 
Can you share the second command I shared as well, that way I can I see what kernels are in grub that aren't installed on the system.
 
Save it as a text file and attach it to your post then.
 
I forgot that grub.cfg is different than before, so I don't think that file will help. Let me see if I can figure it out.
 
Can you run the following and then reboot your system to see if the old kernels are still in the grub menu?
Code:
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg_backup
grub2-mkconfig -o /boot/grub2/grub.cfg
 
cat /boot/grub2/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
set pager=1

if [ -s $prefix/grubenv ]; then
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${saved_entry}"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi

function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}

function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}

terminal_output console
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
set tuned_initrd=""
### END /etc/grub.d/00_tuned ###

### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}
fi
fi
### END /etc/grub.d/01_users ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Red Hat Enterprise Linux Server (3.10.0-1160.53.1.el7.x86_64) 7.9 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.24.1.el7.x86_64-advanced-dd65cb46-756e-4f23-b003-5b4883926f85' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' 60bc64e5-c890-4ba0-8ebe-cd8210cb4bb6
else
search --no-floppy --fs-uuid --set=root 60bc64e5-c890-4ba0-8ebe-cd8210cb4bb6
fi
linux16 /vmlinuz-3.10.0-1160.53.1.el7.x86_64 root=/dev/mapper/rhel-root ro ipv6.disable=1 rd.lvm.lv=rhel/root rd.lvm.lv=backup/swap rhgb quiet fips=1 boot=UUID=60bc64e5-c890-4ba0-8ebe-cd8210cb4bb6 LANG=en_US.UTF-8
initrd16 /initramfs-3.10.0-1160.53.1.el7.x86_64.img
}
menuentry 'Red Hat Enterprise Linux Server (0-rescue-fb20f5f5ef8f434f8fc048eaea3a32a8) 7.9 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-fb20f5f5ef8f434f8fc048eaea3a32a8-advanced-dd65cb46-756e-4f23-b003-5b4883926f85' {
load_video
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' 60bc64e5-c890-4ba0-8ebe-cd8210cb4bb6
else
search --no-floppy --fs-uuid --set=root 60bc64e5-c890-4ba0-8ebe-cd8210cb4bb6
fi
linux16 /vmlinuz-0-rescue-fb20f5f5ef8f434f8fc048eaea3a32a8 root=/dev/mapper/rhel-root ro ipv6.disable=1 rd.lvm.lv=rhel/root rd.lvm.lv=backup/swap rhgb quiet fips=1 boot=UUID=60bc64e5-c890-4ba0-8ebe-cd8210cb4bb6
initrd16 /initramfs-0-rescue-fb20f5f5ef8f434f8fc048eaea3a32a8.img
}
if [ "x$default" = 'Red Hat Enterprise Linux Server (3.10.0-1160.24.1.el7.x86_64) 7.9 (Maipo)' ]; then default='Advanced options for Red Hat Enterprise Linux Server>Red Hat Enterprise Linux Server (3.10.0-1160.24.1.el7.x86_64) 7.9 (Maipo)'; fi;
### END /etc/grub.d/10_linux ###
 
The file grub.cfg is generated automatically so it shouldn't be edited manually. Can you run the following.
Code:
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg_backup
grub2-mkconfig -o /boot/grub2/grub.cfg
Then reboot and see if the kernel currently mentioned in grub.cfg don't show up in the grub menu anymore?
 
When removing/updating/adding kernels grub.cfg should automatically be updated so very strange that the grub.cfg on your system still contains a kernel not installed on your system anymore. Also it maybe worth checking(locate grub.cfg) if there are any other grub.cfg files on your system. I at one point had two grub.cfg files on the system, one with the correct kernels and the other with the incorrect kernels. Good luck!
 

Members online


Top