]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(dracut.sh): check kernel zstd support early
authorMartin Wilck <mwilck@suse.com>
Fri, 19 Nov 2021 13:45:10 +0000 (14:45 +0100)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Fri, 26 Nov 2021 17:01:45 +0000 (17:01 +0000)
Rather than checking late and falling back to "cat" if the kernel
doesn't support zstd decompression, do this early, and use the
fallback code path.

dracut.sh

index c6089ba63a2ef964fd974f519ce17894255dd77e..ce54a851950141779e7c63683101e0d283af5187 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -2350,6 +2350,17 @@ if [[ $create_early_cpio == yes ]]; then
     fi
 fi
 
+if check_kernel_config CONFIG_RD_ZSTD; then
+    DRACUT_KERNEL_RD_ZSTD=yes
+else
+    DRACUT_KERNEL_RD_ZSTD=
+fi
+
+if [[ $compress == $DRACUT_COMPRESS_ZSTD* && ! $DRACUT_KERNEL_RD_ZSTD ]]; then
+    dwarn "dracut: kernel has no zstd support compiled in."
+    compress=
+fi
+
 if [[ $compress && $compress != cat ]]; then
     if ! command -v "${compress%% *}" &> /dev/null; then
         derror "dracut: cannot execute compression command '$compress', falling back to default"
@@ -2360,6 +2371,7 @@ fi
 if ! [[ $compress ]]; then
     # check all known compressors, if none specified
     for i in $DRACUT_COMPRESS_PIGZ $DRACUT_COMPRESS_GZIP $DRACUT_COMPRESS_LZ4 $DRACUT_COMPRESS_LZOP $DRACUT_COMPRESS_ZSTD $DRACUT_COMPRESS_LZMA $DRACUT_COMPRESS_XZ $DRACUT_COMPRESS_LBZIP2 $DRACUT_COMPRESS_BZIP2 $DRACUT_COMPRESS_CAT; do
+        [[ $i != "$DRACUT_COMPRESS_ZSTD" || $DRACUT_KERNEL_RD_ZSTD ]] || continue
         command -v "$i" &> /dev/null || continue
         compress="$i"
         break
@@ -2406,11 +2418,6 @@ case $compress in
         ;;
 esac
 
-if [[ $compress == $DRACUT_COMPRESS_ZSTD* ]] && ! check_kernel_config CONFIG_RD_ZSTD; then
-    dwarn "dracut: kernel has no zstd support compiled in."
-    compress="cat"
-fi
-
 if [[ -n $enhanced_cpio ]]; then
     if [[ $compress == "cat" ]]; then
         # dracut-cpio appends by default, so any ucode remains