Harald Hoyer 1f6198
From 2e7257a2e3bf91c11e8cc56f609b288403f9be14 Mon Sep 17 00:00:00 2001
Harald Hoyer 1f6198
From: Dave Young <dyoung@redhat.com>
Harald Hoyer 1f6198
Date: Thu, 19 Apr 2012 12:01:36 +0800
Harald Hoyer 1f6198
Subject: [PATCH] add pre-pivot-cleanup hook
Harald Hoyer 1f6198
Harald Hoyer 1f6198
Sometimes some hook script will need to be before the cleanup hook scripts
Harald Hoyer 1f6198
For example dhclient killing, nfs cleanup, etc. must not happen before kdump
Harald Hoyer 1f6198
because it will use their fuctionalities.
Harald Hoyer 1f6198
Harald Hoyer 1f6198
So here introduce a new hook pre-pivot-cleanup, all cleanup scripts will go there.
Harald Hoyer 1f6198
that means pre-pivot hook is splited to two hooks pre-pivot and pre-pivot-cleanup
Harald Hoyer 1f6198
Harald Hoyer 1f6198
Signed-off-by: Dave Young <dyoung@redhat.com>
Harald Hoyer 1f6198
---
Harald Hoyer 1f6198
 README.modules           |    3 +++
Harald Hoyer 1f6198
 dracut-functions.sh      |    2 +-
Harald Hoyer 1f6198
 dracut.asc               |    7 ++++++-
Harald Hoyer 1f6198
 dracut.cmdline.7.asc     |    2 +-
Harald Hoyer 1f6198
 modules.d/99base/init.sh |    7 ++++++-
Harald Hoyer 0c26bf
 5 Dateien geändert, 17 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)
Harald Hoyer 1f6198
Harald Hoyer 1f6198
diff --git a/README.modules b/README.modules
Harald Hoyer 1f6198
index 21461de..188d011 100644
Harald Hoyer 1f6198
--- a/README.modules
Harald Hoyer 1f6198
+++ b/README.modules
Harald Hoyer 1f6198
@@ -103,6 +103,9 @@ init has the following hook points to inject scripts:
Harald Hoyer 1f6198
    a timeout.
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
 /lib/dracut/hooks/pre-pivot/*.sh
Harald Hoyer 1f6198
+   scripts to run before latter initramfs cleanups
Harald Hoyer 1f6198
+
Harald Hoyer 1f6198
+/lib/dracut/hooks/pre-pivot-cleanup/*.sh
Harald Hoyer 1f6198
    scripts to run before the real init is executed and the initramfs
Harald Hoyer 1f6198
    disappears
Harald Hoyer 1f6198
    All processes started before should be killed here.
Harald Hoyer 1f6198
diff --git a/dracut-functions.sh b/dracut-functions.sh
Harald Hoyer 1f6198
index f5611dc..ccf3ba6 100755
Harald Hoyer 1f6198
--- a/dracut-functions.sh
Harald Hoyer 1f6198
+++ b/dracut-functions.sh
Harald Hoyer 1f6198
@@ -36,7 +36,7 @@ fi
Harald Hoyer 1f6198
 [[ $hookdirs ]] || {
Harald Hoyer 1f6198
     hookdirs="cmdline pre-udev pre-trigger netroot "
Harald Hoyer 1f6198
     hookdirs+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
Harald Hoyer 1f6198
-    hookdirs+="pre-mount pre-pivot mount "
Harald Hoyer 1f6198
+    hookdirs+="pre-mount pre-pivot pre-pivot-cleanup mount "
Harald Hoyer 1f6198
     hookdirs+="emergency shutdown-emergency shutdown cleanup "
Harald Hoyer 1f6198
     export hookdirs
Harald Hoyer 1f6198
 }
Harald Hoyer 1f6198
diff --git a/dracut.asc b/dracut.asc
Harald Hoyer 1f6198
index 1a0e3d2..9621db2 100644
Harald Hoyer 1f6198
--- a/dracut.asc
Harald Hoyer 1f6198
+++ b/dracut.asc
Harald Hoyer 1f6198
@@ -854,12 +854,17 @@ This hook is mainly to mount the real root device.
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
 === Hook: pre-pivot
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
+This hook is called before pre-pivot-cleanup hook, This is a good place for
Harald Hoyer 1f6198
+actions other than cleanups which need to be called before pivot.
Harald Hoyer 1f6198
+
Harald Hoyer 1f6198
+
Harald Hoyer 1f6198
+=== Hook: pre-pivot-cleanup
Harald Hoyer 1f6198
+
Harald Hoyer 1f6198
 This hook is the last hook and is called before init finally switches root to
Harald Hoyer 1f6198
 the real root device. This is a good place to clean up and kill processes not
Harald Hoyer 1f6198
 needed anymore.
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
-
Harald Hoyer 1f6198
 === Cleanup and switch_root
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
 Init kills all udev processes, cleans up the environment, sets up the arguments
Harald Hoyer 1f6198
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
Harald Hoyer 1f6198
index c77fee5..76db651 100644
Harald Hoyer 1f6198
--- a/dracut.cmdline.7.asc
Harald Hoyer 1f6198
+++ b/dracut.cmdline.7.asc
Harald Hoyer 1f6198
@@ -105,7 +105,7 @@ Debug
Harald Hoyer 1f6198
 **rd.break**::
Harald Hoyer 1f6198
     drop to a shell at the end
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
-**rd.break=**_{cmdline|pre-udev|pre-trigger|initqueue|pre-mount|mount|pre-pivot}_::
Harald Hoyer 1f6198
+**rd.break=**_{cmdline|pre-udev|pre-trigger|initqueue|pre-mount|mount|pre-pivot|pre-pivot-cleanup}_::
Harald Hoyer 1f6198
     drop to a shell on defined breakpoint
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
 **rd.udev.info**::
Harald Hoyer 1f6198
diff --git a/modules.d/99base/init.sh b/modules.d/99base/init.sh
Harald Hoyer 1f6198
index 65bc88f..88ec184 100755
Harald Hoyer 1f6198
--- a/modules.d/99base/init.sh
Harald Hoyer 1f6198
+++ b/modules.d/99base/init.sh
Harald Hoyer 1f6198
@@ -224,10 +224,15 @@ done
Harald Hoyer 1f6198
     while read dev mp rest; do [ "$mp" = "$NEWROOT" ] && echo $dev; done < /proc/mounts
Harald Hoyer 1f6198
 } | vinfo
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
-# pre pivot scripts are sourced just before we switch over to the new root.
Harald Hoyer 1f6198
+# pre pivot scripts are sourced just before we doing cleanup and switch over
Harald Hoyer 1f6198
+# to the new root.
Harald Hoyer 1f6198
 getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot"
Harald Hoyer 1f6198
 source_hook pre-pivot
Harald Hoyer 1f6198
 
Harald Hoyer 1f6198
+# pre pivot cleanup scripts are sourced just before we switch over to the new root.
Harald Hoyer 1f6198
+getarg 'rd.break=pre-pivot-cleanup' 'rdbreak=pre-pivot-cleanup' && emergency_shell -n pre-pivot-cleanup "Break pre-pivot-cleanup"
Harald Hoyer 1f6198
+source_hook pre-pivot-cleanup
Harald Hoyer 1f6198
+
Harald Hoyer 1f6198
 # By the time we get here, the root filesystem should be mounted.
Harald Hoyer 1f6198
 # Try to find init. 
Harald Hoyer 1f6198
 for i in "$(getarg real_init=)" "$(getarg init=)" $(getargs rd.distroinit=) /sbin/init; do