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