Cleaning old kernels and update boot menu

Hi,
When removing old kernels the old kernels are still displayed in the boot menu.

Looks like menu entries are not deleted from /boot/loader/entries
Is there any method to automatically remove related config for removed kernels?

How are you removing them? Usually when you remove them using rpm/dnf the kernel grub entries update and they disappear.

There is even a specific option in dnf to do the kernel cleanup: dnf remove --oldinstallonly

2 Likes

I found the reason.
Since I’m using template to provision new VMs there are some old entries created by os before templating.

[root@lb2 ~]# ll /boot/loader/entries/
total 32
-rw-r--r--. 1 root root 461 Jan 25 22:56 5a2a33048d8046f18831c4c961a0d1c6-0-rescue.conf
-rw-r--r--. 1 root root 409 Jan 25 22:54 5a2a33048d8046f18831c4c961a0d1c6-5.14.0-503.22.1.el9_5.x86_64.conf
-rw-r--r--. 1 root root 409 Feb 28 23:54 5a2a33048d8046f18831c4c961a0d1c6-5.14.0-503.26.1.el9_5.x86_64.conf
-rw-r--r--. 1 root root 409 Apr 13 17:18 5a2a33048d8046f18831c4c961a0d1c6-5.14.0-503.35.1.el9_5.x86_64.conf
-rw-r--r--. 1 root root 462 Oct  5  2024 d7027b39191b4539ad7ef6bbd69496ef-0-rescue.conf
-rw-r--r--. 1 root root 410 Oct  5  2024 d7027b39191b4539ad7ef6bbd69496ef-5.14.0-427.37.1.el9_4.x86_64.conf
-rw-r--r--. 1 root root 409 Nov 24 20:52 d7027b39191b4539ad7ef6bbd69496ef-5.14.0-503.14.1.el9_5.x86_64.conf
-rw-r--r--. 1 root root 409 Dec  7 22:39 d7027b39191b4539ad7ef6bbd69496ef-5.14.0-503.15.1.el9_5.x86_64.conf

[root@lb2 ~]# cat /etc/machine-id 
5a2a33048d8046f18831c4c961a0d1c6

This method works like a charm!

1 Like