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