]>
git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/99shutdown/shutdown.sh
d6a532b0c213c7957d223515a0fcf6328be7a403
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # Licensed under the GPLv2
7 # Copyright 2011, Red Hat, Inc.
8 # Harald Hoyer <harald@redhat.com>
11 [ -w /dev
/console
] && exec </dev
/console
>>/dev
/console
2>>/dev
/console
14 export PATH
=/usr
/sbin
:/usr
/bin
:/sbin
:/bin
18 for i
in sys proc run dev
; do
20 mount
--move /oldroot
/$i /oldsys
/$i
23 # if "kexec" was installed after creating the initramfs, we try to copy it from the real root
24 # libz normally is pulled in via kmod/modprobe and udevadm
25 if [ "$ACTION" = "kexec" ] && ! command -v kexec
>/dev
/null
2>&1; then
26 for p
in /usr
/sbin
/usr
/bin
/sbin
/bin
; do
27 cp -a /oldroot
/${p}/kexec
$p >/dev
/null
2>&1 && break
32 trap "emergency_shell --shutdown shutdown Signal caught!" 0
33 getarg
'rd.break=pre-shutdown' && emergency_shell
--shutdown pre-shutdown
"Break before pre-shutdown"
35 source_hook pre-shutdown
37 warn
"Killing all remaining processes"
39 killall_proc_mountpoint
/oldroot
44 if strstr
"$mp" oldroot
; then
52 [ "$_did_umount" = "y" ] && return 0
57 while [ $_cnt -le 40 ]; do
58 umount_a
2>/dev
/null ||
break
62 [ $_cnt -ge 40 ] && umount_a
64 if strstr
"$(cat /proc/mounts)" "/oldroot"; then
65 warn
"Cannot umount /oldroot"
66 for _pid
in /proc
/*; do
71 [ -e /proc
/$_pid/exe
] ||
continue
72 [ -e /proc
/$_pid/root
] ||
continue
73 if strstr
"$(ls -l /proc/$_pid /proc/$_pid/fd 2>/dev/null)" "oldroot"; then
74 warn
"Blocking umount of /oldroot [$_pid] $(cat /proc/$_pid/cmdline)"
75 elif [ $_pid -ne $$
]; then
76 warn
"Still running [$_pid] $(cat /proc/$_pid/cmdline)"
78 ls -l /proc
/$_pid/fd
2>&1 | vwarn
85 for __f
in $hookdir/shutdown
/*.sh
; do
86 [ -e "$__f" ] ||
continue
96 while _check_shutdown
; do
101 getarg
'rd.break=shutdown' && emergency_shell
--shutdown shutdown
"Break before shutdown"
104 reboot|poweroff|halt
)
106 warn
"$ACTION failed!"
110 warn
"$ACTION failed!"
113 warn
"Shutdown called with argument '$ACTION'. Rebooting!"
118 emergency_shell
--shutdown shutdown