28ab1c
From f24f363eb329f8ce4b2435fb5d14786c104dec99 Mon Sep 17 00:00:00 2001
28ab1c
From: Kairui Song <kasong@redhat.com>
28ab1c
Date: Mon, 2 Aug 2021 13:33:18 +0200
28ab1c
Subject: [PATCH] fix(squash): fixes related to squash module rebase
28ab1c
28ab1c
fix fro missing dracutsysrootdir
28ab1c
move the $compress args parsing to later part after mksquashfs, so mksquashfs can use $compress as the original parameter value
28ab1c
28ab1c
Related:#1959336
28ab1c
---
28ab1c
 dracut.sh                          | 94 +++++++++++++++++++-------------------
28ab1c
 modules.d/99squash/module-setup.sh |  3 +-
28ab1c
 2 files changed, 49 insertions(+), 48 deletions(-)
28ab1c
28ab1c
diff --git a/dracut.sh b/dracut.sh
28ab1c
index fa14e3ce..e559bb96 100755
28ab1c
--- a/dracut.sh
28ab1c
+++ b/dracut.sh
28ab1c
@@ -825,53 +825,6 @@ if [[ $_no_compress_l = "cat" ]]; then
28ab1c
     compress="cat"
28ab1c
 fi
28ab1c
 
28ab1c
-if ! [[ $compress ]]; then
28ab1c
-    # check all known compressors, if none specified
28ab1c
-    for i in pigz gzip lz4 lzop zstd lzma xz lbzip2 bzip2 cat; do
28ab1c
-        command -v "$i" &>/dev/null || continue
28ab1c
-        compress="$i"
28ab1c
-        break
28ab1c
-    done
28ab1c
-    if [[ $compress = cat ]]; then
28ab1c
-            printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
28ab1c
-    fi
28ab1c
-fi
28ab1c
-
28ab1c
-# choose the right arguments for the compressor
28ab1c
-case $compress in
28ab1c
-    bzip2|lbzip2)
28ab1c
-        if [[ "$compress" =  lbzip2 ]] || command -v lbzip2 &>/dev/null; then
28ab1c
-            compress="lbzip2 -9"
28ab1c
-        else
28ab1c
-            compress="bzip2 -9"
28ab1c
-        fi
28ab1c
-        ;;
28ab1c
-    lzma)
28ab1c
-        compress="lzma -9 -T0"
28ab1c
-        ;;
28ab1c
-    xz)
28ab1c
-        compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
28ab1c
-        ;;
28ab1c
-    gzip|pigz)
28ab1c
-        if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
28ab1c
-            compress="pigz -9 -n -T -R"
28ab1c
-        elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
28ab1c
-            compress="gzip -n -9 --rsyncable"
28ab1c
-        else
28ab1c
-            compress="gzip -n -9"
28ab1c
-        fi
28ab1c
-        ;;
28ab1c
-    lzo|lzop)
28ab1c
-        compress="lzop -9"
28ab1c
-        ;;
28ab1c
-    lz4)
28ab1c
-        compress="lz4 -l -9"
28ab1c
-        ;;
28ab1c
-    zstd)
28ab1c
-       compress="zstd -15 -q -T0"
28ab1c
-       ;;
28ab1c
-esac
28ab1c
-
28ab1c
 [[ $hostonly = yes ]] && hostonly="-h"
28ab1c
 [[ $hostonly != "-h" ]] && unset hostonly
28ab1c
 
28ab1c
@@ -1848,6 +1801,53 @@ if [[ $create_early_cpio = yes ]]; then
28ab1c
     fi
28ab1c
 fi
28ab1c
 
28ab1c
+if ! [[ $compress ]]; then
28ab1c
+    # check all known compressors, if none specified
28ab1c
+    for i in pigz gzip lz4 lzop zstd lzma xz lbzip2 bzip2 cat; do
28ab1c
+        command -v "$i" &>/dev/null || continue
28ab1c
+        compress="$i"
28ab1c
+        break
28ab1c
+    done
28ab1c
+    if [[ $compress = cat ]]; then
28ab1c
+            printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
28ab1c
+    fi
28ab1c
+fi
28ab1c
+
28ab1c
+# choose the right arguments for the compressor
28ab1c
+case $compress in
28ab1c
+    bzip2|lbzip2)
28ab1c
+        if [[ "$compress" =  lbzip2 ]] || command -v lbzip2 &>/dev/null; then
28ab1c
+            compress="lbzip2 -9"
28ab1c
+        else
28ab1c
+            compress="bzip2 -9"
28ab1c
+        fi
28ab1c
+        ;;
28ab1c
+    lzma)
28ab1c
+        compress="lzma -9 -T0"
28ab1c
+        ;;
28ab1c
+    xz)
28ab1c
+        compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
28ab1c
+        ;;
28ab1c
+    gzip|pigz)
28ab1c
+        if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
28ab1c
+            compress="pigz -9 -n -T -R"
28ab1c
+        elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
28ab1c
+            compress="gzip -n -9 --rsyncable"
28ab1c
+        else
28ab1c
+            compress="gzip -n -9"
28ab1c
+        fi
28ab1c
+        ;;
28ab1c
+    lzo|lzop)
28ab1c
+        compress="lzop -9"
28ab1c
+        ;;
28ab1c
+    lz4)
28ab1c
+        compress="lz4 -l -9"
28ab1c
+        ;;
28ab1c
+    zstd)
28ab1c
+       compress="zstd -15 -q -T0"
28ab1c
+       ;;
28ab1c
+esac
28ab1c
+
28ab1c
 if ! (
28ab1c
         umask 077; cd "$initdir"
28ab1c
         find . -print0 | sort -z \
28ab1c
diff --git a/modules.d/99squash/module-setup.sh b/modules.d/99squash/module-setup.sh
28ab1c
index 14790ce8..11964b97 100644
28ab1c
--- a/modules.d/99squash/module-setup.sh
28ab1c
+++ b/modules.d/99squash/module-setup.sh
28ab1c
@@ -39,9 +39,10 @@ installpost() {
28ab1c
 
28ab1c
     # Copy dracut spec files out side of the squash image
28ab1c
     # so dracut rebuild and lsinitrd can work
28ab1c
+    mkdir -p "$initdir/usr/lib/dracut/"
28ab1c
     for file in "$squash_dir"/usr/lib/dracut/*; do
28ab1c
         [[ -f $file ]] || continue
28ab1c
-        DRACUT_RESOLVE_DEPS=1 dracutsysrootdir="$squash_dir" inst "${file#$squash_dir}"
28ab1c
+        cp "$file" "$initdir/${file#$squash_dir}"
28ab1c
     done
28ab1c
 
28ab1c
     # Install required modules and binaries for the squash image init script.
28ab1c