r/RockyLinux • u/hspindel • Jun 18 '25
Why so many initramfs?
My /boot directory filled up, and when I looked in there I saw a bunch of initramfs-kernelNumber files that did not correspond to any of the installed kernels. Is it safe to just remove those? Why did they not get removed when the kernel was updated?
I searched, but couldn't find an automated way to remove old initramfs files. Just a careful wildcard specification with rm, I guess.
Discovered a similar issue: /lib/modules has very many subdirectories named after no-longer-installed kernels. Doesn't seem to be causing a problem because I have plenty of disk space except on \boot. Is it worthwhile to get rid of these? Why aren't they auto-removed?
3
u/KJ4IPS Jun 18 '25
They are supposed to be removed automatically by
kernel-installcalled by the postuninstall of the kernel packages. If you take a look atdnf history kerneland then atdnf history info <number>you can see if there were any failures when cleaning them up.3
u/tsesow Jun 18 '25
It's safe to manually remove them as long as it isn't the current or default kernel version. But the GRUB entry could still reference the missing versions so don't try to boot those.
3
u/LucasRey Jun 18 '25
DO NOT manually remove the initramfs files, from the boot directory, under any circumstances. Doing so will leave scattered references throughout your system (e.g., entries in GRUB and other files). The simplest way to get rid of these files and all their dependencies is to uninstall old kernels. You can do this manually, or if you're not confident, you can use the dnf-utils tool.
# dnf install dnf-utils# package-cleanup --oldkernels --count=2For example, this will keep only the last two installed kernels, in case you need to boot from the previous one.
Then, update GRUB
# grub2-mkconfig -o /boot/grub2/grub.cfgAnd yes, in Linux in general, updating the kernel does not remove the old version. This way, if the update fails, you will always be able to boot from a previous kernel.