28ab1c
From 0c2ac6b7503661948ead031f745736e35fef2e3f Mon Sep 17 00:00:00 2001
28ab1c
From: Kairui Song <kasong@redhat.com>
28ab1c
Date: Wed, 26 Dec 2018 17:38:02 +0800
28ab1c
Subject: [PATCH] lsinitrd: list squash content as well
28ab1c
28ab1c
When the initramfs is built with squash module enabled, the content
28ab1c
inside squash image will be invisible from the lsinitrd tool. This
28ab1c
commit make lsinitrd detect and list the content of the squash image as
28ab1c
well to avoid possible confusion.
28ab1c
28ab1c
Signed-off-by: Kairui Song <kasong@redhat.com>
28ab1c
(cherry picked from commit 1ff306a3964840fc548188a8aa4862143b347e8a)
28ab1c
28ab1c
Resolves: #1959336
28ab1c
---
28ab1c
 lsinitrd.sh | 16 ++++++++++++++++
28ab1c
 1 file changed, 16 insertions(+)
28ab1c
28ab1c
diff --git a/lsinitrd.sh b/lsinitrd.sh
28ab1c
index a2fa4d7a..0b42b9a4 100755
28ab1c
--- a/lsinitrd.sh
28ab1c
+++ b/lsinitrd.sh
28ab1c
@@ -160,6 +160,21 @@ list_files()
28ab1c
     echo "========================================================================"
28ab1c
 }
28ab1c
 
28ab1c
+list_squash_content()
28ab1c
+{
28ab1c
+    SQUASH_IMG="squash/root.img"
28ab1c
+    SQUASH_TMPFILE="$(mktemp -t --suffix=.root.sqsh lsinitrd.XXXXXX)"
28ab1c
+    trap "rm -f '$SQUASH_TMPFILE'" EXIT
28ab1c
+    $CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --to-stdout -- \
28ab1c
+        $SQUASH_IMG > "$SQUASH_TMPFILE" 2>/dev/null
28ab1c
+    if [[ -s $SQUASH_TMPFILE ]]; then
28ab1c
+        echo "Squashed content ($SQUASH_IMG):"
28ab1c
+        echo "========================================================================"
28ab1c
+        unsquashfs -ll "$SQUASH_TMPFILE" | tail -n +4
28ab1c
+        echo "========================================================================"
28ab1c
+    fi
28ab1c
+}
28ab1c
+
28ab1c
 unpack_files()
28ab1c
 {
28ab1c
     if (( ${#filenames[@]} > 0 )); then
28ab1c
@@ -287,6 +302,7 @@ else
28ab1c
         echo
28ab1c
         list_modules
28ab1c
         list_files
28ab1c
+        list_squash_content
28ab1c
     fi
28ab1c
 fi
28ab1c
 
28ab1c