initramfs: Prevent creating the minimal initrd if kernel was uninstalled

This condition should be a unusual, but it's possible if users are
installing kdumpst right after a kernel upgrade, without rebooting
for example. To achieve this, just check if the modules dir exists.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
This commit is contained in:
Guilherme G. Piccoli
2024-01-05 19:18:06 +00:00
parent c83ad9a83e
commit 512cd8ff4a

View File

@ -15,6 +15,19 @@ if [ -n "$1" ]; then
if command -v INITRD 1>/dev/null; then if command -v INITRD 1>/dev/null; then
INITRD_installation INITRD_installation
# Worth noticing that it is possible (though unlikely) that during
# the kdumpst package installation, users are running a previously
# uninstalled kernel. Imagine if the user upgrades the kernel, and
# then install kdumpst before rebooting. With that, creating an
# initrd fails here since it relies on "uname -r". To prevent such
# unhandled error, check if this kernel's modules directory exists.
if [ ! -d "/lib/modules/$1" ]; then
logger "kdumpst: no kernel modules dir; defer initrd creation to next boot"
exit 0
fi
create_initramfs_INITRD "$1" create_initramfs_INITRD "$1"
fi fi
exit 0 exit 0