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