From 4a44eee472745f8dd43b18815851bd668b7497da Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 25 Dec 2018 22:51:35 +0800 Subject: [PATCH] dracut-module-setup: Don't build squashed image if required modules are missing When someone is using a minimal kernel without squash module installed, including squash dracut module will either either fail to build or fail to boot the initramfs. As kdump always build the image for one single kernel, we can safely just use modprobe to check if a modules is already built in, or it exists and loadable for the kernel we are using for kdump image, and don't include the squash module if they are missing. Everything will still work just fine without squash module. We do the check in kdump dracut modules not in squash dracut module because kdump dracut module could leverage of the KDUMP_KERNELVER variable to know which kernel it should check against, squash dracut module may be used to build for a generic image. And we only check for the kernel module dependency, other binary dependencies are either well checked or well declared in dracut. Signed-off-by: Kairui Song Acked-by: Dave Young --- dracut-module-setup.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 7499678..db7cd23 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -18,7 +18,23 @@ check() { } depends() { - local _dep="base shutdown squash" + local _dep="base shutdown" + + is_squash_available() { + for kmodule in squashfs overlay loop; do + if [ -z "$KDUMP_KERNELVER" ]; then + modprobe --dry-run $kmodule &>/dev/null || return 1 + else + modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1 + fi + done + } + + if is_squash_available; then + _dep="$_dep squash" + else + dwarning "Required modules to build a squashed kdump image is missing!" + fi if [ -n "$( find /sys/devices -name drm )" ] || [ -d /sys/module/hyperv_fb ]; then _dep="$_dep drm"