From 178c189b0b3f83d3339a30ad4846a159b0e6e5d0 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Mon, 8 Oct 2012 15:37:04 +0200 Subject: [PATCH] shutdown/shutdown.sh: failsafe shutdown for kexec copy kexec from the real root, if it is not found in the unpacked initramfs for shutdown. Also drop to an emergency shell, if we can't do the ACTION --- modules.d/99shutdown/shutdown.sh | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/modules.d/99shutdown/shutdown.sh b/modules.d/99shutdown/shutdown.sh index 74b6be8..1a6ac31 100755 --- a/modules.d/99shutdown/shutdown.sh +++ b/modules.d/99shutdown/shutdown.sh @@ -12,6 +12,15 @@ export TERM=linux export PATH=/usr/sbin:/usr/bin:/sbin:/bin . /lib/dracut-lib.sh +# if "kexec" was installed after creating the initramfs, we try to copy it from the real root +# libz normally is pulled in via kmod/modprobe and udevadm +if [ "$ACTION" = "kexec" ] && ! command -v kexec >/dev/null 2>&1; then + for p in /usr/sbin /usr/bin /sbin /bin; do + cp -a /oldroot/${p}/kexec $p >/dev/null 2>&1 && break + done + hash kexec +fi + trap "emergency_shell --shutdown shutdown Signal caught!" 0 getarg 'rd.break=pre-shutdown' && emergency_shell --shutdown pre-shutdown "Break before pre-shutdown" @@ -56,10 +65,20 @@ done _check_shutdown final getarg 'rd.break=shutdown' && emergency_shell --shutdown shutdown "Break before shutdown" -[ "$ACTION" = "reboot" ] && reboot -f -d -n -[ "$ACTION" = "poweroff" ] && poweroff -f -d -n -[ "$ACTION" = "halt" ] && halt -f -d -n -[ "$ACTION" = "kexec" ] && kexec -e -warn "Shutdown called without an argument. Rebooting!" -reboot -f -d -n +case "$ACTION" in + reboot|poweroff|halt) + $ACTION -f -d -n + warn "$ACTION failed!" + ;; + kexec) + kexec -e + warn "$ACTION failed!" + ;; + *) + warn "Shutdown called with argument '$ACTION'. Rebooting!" + reboot -f -d -n + ;; +esac + +emergency_shell --shutdown shutdown -- 2.7.4