From: Harald Hoyer Date: Mon, 8 Oct 2012 13:37:04 +0000 (+0200) Subject: shutdown/shutdown.sh: failsafe shutdown for kexec X-Git-Tag: 024~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=178c189b0b3f83d3339a30ad4846a159b0e6e5d0;p=thirdparty%2Fdracut.git 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 --- diff --git a/modules.d/99shutdown/shutdown.sh b/modules.d/99shutdown/shutdown.sh index 74b6be84d..1a6ac31ae 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