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