ab92d3
From 0a2f7b1779ddcac1c4e79aa58212c7ee528ac6e1 Mon Sep 17 00:00:00 2001
ab92d3
From: Kairui Song <kasong@redhat.com>
ab92d3
Date: Mon, 15 Feb 2021 23:15:26 +0800
ab92d3
Subject: [PATCH] feat: squash module follow --compress option
ab92d3
ab92d3
Try to make mksquashfs follow --compress option if squash module is
ab92d3
included, if not specified or invalid, fall back to use mksquashfs's
ab92d3
default compressor.
ab92d3
ab92d3
(cherry picked from commit 5d05ffbd87bc27e27f517ebc3454d50729c687e6)
ab92d3
ab92d3
Cherry-picked from: 5d05ffbd
ab92d3
Resolves: #1959336
ab92d3
---
ab92d3
 dracut.sh | 17 ++++++++++++++---
ab92d3
 1 file changed, 14 insertions(+), 3 deletions(-)
ab92d3
ab92d3
diff --git a/dracut.sh b/dracut.sh
ab92d3
index b403f401..d9a66c5a 100755
ab92d3
--- a/dracut.sh
ab92d3
+++ b/dracut.sh
ab92d3
@@ -1781,14 +1781,25 @@ fi
ab92d3
 
ab92d3
 if dracut_module_included "squash"; then
ab92d3
     dinfo "*** Squashing the files inside the initramfs ***"
ab92d3
-    mksquashfs $squash_dir $squash_img -no-xattrs -no-exports -noappend -always-use-fragments -comp xz -Xdict-size 100% -no-progress 1> /dev/null
ab92d3
+    declare squash_compress_arg
ab92d3
+    # shellcheck disable=SC2086
ab92d3
+    if [[ $compress ]]; then
ab92d3
+        if ! mksquashfs /dev/null "$DRACUT_TMPDIR"/.squash-test.img -no-progress -comp $compress &>/dev/null; then
ab92d3
+            dwarn "mksquashfs doesn't support compressor '$compress', failing back to default compressor."
ab92d3
+        else
ab92d3
+            squash_compress_arg="$compress"
ab92d3
+        fi
ab92d3
+    fi
ab92d3
 
ab92d3
-    if [[ $? != 0 ]]; then
ab92d3
+    # shellcheck disable=SC2086
ab92d3
+    if ! mksquashfs "$squash_dir" "$squash_img" \
ab92d3
+        -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \
ab92d3
+        -no-progress ${squash_compress_arg:+-comp $squash_compress_arg} 1> /dev/null; then
ab92d3
         dfatal "dracut: Failed making squash image"
ab92d3
         exit 1
ab92d3
     fi
ab92d3
 
ab92d3
-    rm -rf $squash_dir
ab92d3
+    rm -rf "$squash_dir"
ab92d3
     dinfo "*** Squashing the files inside the initramfs done ***"
ab92d3
 fi
ab92d3
 
ab92d3