6df2a7
From cbebaacfd05c55fddd11b3090983a2be1d2b48d3 Mon Sep 17 00:00:00 2001
6df2a7
From: Kairui Song <kasong@redhat.com>
6df2a7
Date: Wed, 17 Jul 2019 17:10:36 +0800
6df2a7
Subject: [PATCH] dracut.sh: Adjust squash and strip order
6df2a7
6df2a7
Previously with squash module, some binaries will be reinstalled, but
6df2a7
stripping happens before that so new installed binaries is not stripped.
6df2a7
So adjust the squash and strip order, ensure new installed binaries are
6df2a7
stripped just the same way with the old binaries.
6df2a7
6df2a7
Also split squash into two stage to make the split easier, move the
6df2a7
squash temp dir into initdir so stripping will cover that too,
6df2a7
and print more usefule message.
6df2a7
6df2a7
Signed-off-by: Kairui Song <kasong@redhat.com>
6df2a7
(cherry picked from commit 6a74c03b4a8472fb090015b32e652edfeadb5a10)
6df2a7
6df2a7
Resolves: #1776659
6df2a7
---
6df2a7
 dracut.sh | 43 +++++++++++++++++++++++++------------------
6df2a7
 1 file changed, 25 insertions(+), 18 deletions(-)
6df2a7
6df2a7
diff --git a/dracut.sh b/dracut.sh
6df2a7
index 223261d6..310646e3 100755
6df2a7
--- a/dracut.sh
6df2a7
+++ b/dracut.sh
6df2a7
@@ -1659,21 +1659,6 @@ for d in $(ldconfig_paths); do
6df2a7
     rmdir -p --ignore-fail-on-non-empty "$initdir/$d" >/dev/null 2>&1
6df2a7
 done
6df2a7
 
6df2a7
-if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
6df2a7
-    dinfo "*** Stripping files ***"
6df2a7
-    find "$initdir" -type f \
6df2a7
-        -executable -not -path '*/lib/modules/*.ko' -print0 \
6df2a7
-        | xargs -r -0 $strip_cmd -g -p 2>/dev/null
6df2a7
-
6df2a7
-    # strip kernel modules, but do not touch signed modules
6df2a7
-    find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
6df2a7
-        | while read -r -d $'\0' f || [ -n "$f" ]; do
6df2a7
-        SIG=$(tail -c 28 "$f" | tr -d '\000')
6df2a7
-        [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
6df2a7
-    done | xargs -r -0 $strip_cmd -g -p
6df2a7
-
6df2a7
-    dinfo "*** Stripping files done ***"
6df2a7
-fi
6df2a7
 if [[ $early_microcode = yes ]]; then
6df2a7
     dinfo "*** Generating early-microcode cpio image ***"
6df2a7
     ucode_dir=(amd-ucode intel-ucode)
6df2a7
@@ -1745,9 +1730,8 @@ if [[ $hostonly_cmdline == "yes" ]] ; then
6df2a7
     fi
6df2a7
 fi
6df2a7
 
6df2a7
-dinfo "*** Creating image file '$outfile' ***"
6df2a7
-
6df2a7
 if dracut_module_included "squash"; then
6df2a7
+    dinfo "*** Install squash loader ***"
6df2a7
     if ! check_kernel_config CONFIG_SQUASHFS; then
6df2a7
         dfatal "CONFIG_SQUASHFS have to be enabled for dracut squash module to work"
6df2a7
         exit 1
6df2a7
@@ -1761,7 +1745,7 @@ if dracut_module_included "squash"; then
6df2a7
         exit 1
6df2a7
     fi
6df2a7
 
6df2a7
-    readonly squash_dir="${DRACUT_TMPDIR}/squashfs"
6df2a7
+    readonly squash_dir="$initdir/squash/root"
6df2a7
     readonly squash_img=$initdir/squash/root.img
6df2a7
 
6df2a7
     # Currently only move "usr" "etc" to squashdir
6df2a7
@@ -1854,15 +1838,38 @@ if dracut_module_included "squash"; then
6df2a7
             fi
6df2a7
         done
6df2a7
     done
6df2a7
+fi
6df2a7
 
6df2a7
+if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
6df2a7
+    dinfo "*** Stripping files ***"
6df2a7
+    find "$initdir" -type f \
6df2a7
+        -executable -not -path '*/lib/modules/*.ko' -print0 \
6df2a7
+        | xargs -r -0 $strip_cmd -g -p 2>/dev/null
6df2a7
+
6df2a7
+    # strip kernel modules, but do not touch signed modules
6df2a7
+    find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
6df2a7
+        | while read -r -d $'\0' f || [ -n "$f" ]; do
6df2a7
+        SIG=$(tail -c 28 "$f" | tr -d '\000')
6df2a7
+        [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
6df2a7
+    done | xargs -r -0 $strip_cmd -g -p
6df2a7
+    dinfo "*** Stripping files done ***"
6df2a7
+fi
6df2a7
+
6df2a7
+if dracut_module_included "squash"; then
6df2a7
+    dinfo "*** Squashing the files inside the initramfs ***"
6df2a7
     mksquashfs $squash_dir $squash_img -comp xz -b 64K -Xdict-size 100% &> /dev/null
6df2a7
 
6df2a7
     if [[ $? != 0 ]]; then
6df2a7
         dfatal "dracut: Failed making squash image"
6df2a7
         exit 1
6df2a7
     fi
6df2a7
+
6df2a7
+    rm -rf $squash_dir
6df2a7
+    dinfo "*** Squashing the files inside the initramfs done ***"
6df2a7
 fi
6df2a7
 
6df2a7
+dinfo "*** Creating image file '$outfile' ***"
6df2a7
+
6df2a7
 if [[ $uefi = yes ]]; then
6df2a7
     readonly uefi_outdir="$DRACUT_TMPDIR/uefi"
6df2a7
     mkdir "$uefi_outdir"
6df2a7