Description of problem: We see a couple of customers getting their /boot filled with initramfs files for non-existing kernels (as shown by "rpm -q kernel-core"). It appears that "dracut --regenerate-all" bases itself on the existence of /lib/modules/<KVERS> directory, which leads to creating non-usable initramfs files for removed kernels that still have the directory existing, for example because of presence of 3rd party kernel modules. Filing as Medium/Medium because this leads to space issues in /boot and there is no simple recovery but deleting. Version-Release number of selected component (if applicable): dracut-049 How reproducible: Always Steps to Reproduce: 1. Create directory for some non-installed kernel # mkdir /lib/modules/4.18.0-372.9.1.el8.x86_64 2. Execute dracut # dracut /tmp/foo.img 4.18.0-372.9.1.el8.x86_64 Actual results: /tmp/foo.img created Expected results: Some error Additional info: I think dracut should check that there is really some kernel available, e.g. through checking presence of /boot/vmlinuz-<KVERS>, or failing if some critical kernel files are missing.
It's unclear when the kernel removal leaves files behind, it looks like it's due to some 3rd party script executing. Anyway, for the hardening of dracut, please find below an example of listing making dracut generate a dumb initramfs "polluting" /boot: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- # ll /lib/modules/4.18.0-193.el8.x86_64 total 24 drwxrwxrwx. 3 1002 1012 21 May 21 2022 kernel -rw-rw-rw-. 1 1002 1012 45 May 19 08:54 modules.alias -rw-rw-rw-. 1 1002 1012 12 May 19 08:54 modules.alias.bin -rw-rw-rw-. 1 1002 1012 0 May 19 08:54 modules.builtin.bin -rw-rw-rw-. 1 1002 1012 0 May 19 08:54 modules.dep -rw-rw-rw-. 1 1002 1012 12 May 19 08:54 modules.dep.bin -rw-rw-rw-. 1 1002 1012 0 May 19 08:54 modules.devname -rw-rw-rw-. 1 1002 1012 55 May 19 08:54 modules.softdep -rw-rw-rw-. 1 1002 1012 49 May 19 08:54 modules.symbols -rw-rw-rw-. 1 1002 1012 12 May 19 08:54 modules.symbols.bin -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- Here above all non-binary files are "empty" or just contain comments: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- # cat modules.alias modules.softdep modules.symbols # Aliases extracted from modules themselves. # Soft dependencies extracted from modules themselves. # Aliases for symbols, used by symbol_request(). -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- This leads to generating a large but useless initramfs: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- # dracut /tmp/test.img 4.18.0-193.el8.x86_64 depmod: WARNING: could not open /var/tmp/dracut.YTEvX1/initramfs/lib/modules/4.18.0-193.el8.x86_64/modules.order: No such file or directory depmod: WARNING: could not open /var/tmp/dracut.YTEvX1/initramfs/lib/modules/4.18.0-193.el8.x86_64/modules.builtin: No such file or directory Warning no default label for /tmp/test.img # ll /tmp/test.img -rw-------. 1 root root 25489249 Aug 7 17:49 /tmp/test.img -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------