9f65cc
From 20ea91703b98708579f3d531823ec56bcec2bf1a Mon Sep 17 00:00:00 2001
9f65cc
From: Kairui Song <kasong@redhat.com>
9f65cc
Date: Fri, 9 Nov 2018 10:48:28 +0800
9f65cc
Subject: [PATCH] squash: unsquash the root image instead of mounting it on
9f65cc
 shutdown
9f65cc
9f65cc
When building squash image, squash module forgot to install the new
9f65cc
shutdown.sh, and the shutdown hooks are always skipped on ordinary
9f65cc
shutdown if squash module is enabled.
9f65cc
9f65cc
The new shutdown.sh will remount the squash image and then everything
9f65cc
will just work, but currently re-mounting the squash image on shutdown
9f65cc
may have selinux problem and make the system hang, and there is no
9f65cc
easy way to fix it.
9f65cc
9f65cc
So skip fixing the shutdown.sh not being install problem, instead
9f65cc
just drop the new shutdown.sh, and unsquash the image on ordinary
9f65cc
shutdown, which is safer and should always work.
9f65cc
9f65cc
Signed-off-by: Kairui Song <kasong@redhat.com>
9f65cc
(cherry picked from commit a60af534132828fd46fa017291f7ed7cfeab1dc3)
9f65cc
9f65cc
Resolves: #1959336
9f65cc
---
9f65cc
 dracut-initramfs-restore.sh    | 9 +++++++++
9f65cc
 dracut.sh                      | 2 --
9f65cc
 modules.d/99squash/shutdown.sh | 7 -------
9f65cc
 3 files changed, 9 insertions(+), 9 deletions(-)
9f65cc
9f65cc
diff --git a/dracut-initramfs-restore.sh b/dracut-initramfs-restore.sh
9f65cc
index 94794804..67fc88fa 100644
9f65cc
--- a/dracut-initramfs-restore.sh
9f65cc
+++ b/dracut-initramfs-restore.sh
9f65cc
@@ -40,4 +40,13 @@ else
9f65cc
     exit 1
9f65cc
 fi
9f65cc
 
9f65cc
+if [[ -d squash ]]; then
9f65cc
+    unsquashfs -no-xattrs -f -d . squash/root.img >/dev/null
9f65cc
+    if [ $? -ne 0 ]; then
9f65cc
+        echo "Squash module is enabled for this initramfs but failed to unpack squash/root.img" >&2
9f65cc
+        rm -f -- /run/initramfs/shutdown
9f65cc
+        exit 1
9f65cc
+    fi
9f65cc
+fi
9f65cc
+
9f65cc
 exit 0
9f65cc
diff --git a/dracut.sh b/dracut.sh
9f65cc
index f8e68ccb..966350c5 100755
9f65cc
--- a/dracut.sh
9f65cc
+++ b/dracut.sh
9f65cc
@@ -1817,9 +1817,7 @@ if dracut_module_included "squash"; then
9f65cc
     done
9f65cc
 
9f65cc
     mv $initdir/init $initdir/init.stock
9f65cc
-    mv $initdir/shutdown $initdir/shutdown.stock
9f65cc
     ln -s squash/init.sh $initdir/init
9f65cc
-    ln -s squash/shutdown.sh $initdir/shutdown
9f65cc
 
9f65cc
     # Reinstall required files for the squash image setup script.
9f65cc
     # We have moved them inside the squashed image, but they need to be
9f65cc
diff --git a/modules.d/99squash/shutdown.sh b/modules.d/99squash/shutdown.sh
9f65cc
deleted file mode 100755
9f65cc
index 535779f4..00000000
9f65cc
--- a/modules.d/99squash/shutdown.sh
9f65cc
+++ /dev/null
9f65cc
@@ -1,7 +0,0 @@
9f65cc
-#!/bin/sh
9f65cc
-/squash/setup-squash.sh
9f65cc
-
9f65cc
-exec /shutdown.stock
9f65cc
-
9f65cc
-echo "Something went wrong when trying to start original shutdown executable!"
9f65cc
-exit 1
9f65cc