blob: 7fb12935c2f344f978bac2e945eea85a867b3fd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/kexec-tools/files/kexec.init,v 1.11 2008/03/21 09:43:55 genstef Exp $
depend() {
need localmount
}
image_path() {
local x= kver=$(uname -r)
for x in "${KNAME:-bzImage}" vmlinuz \
bzImage-"${kver}" vmlinuz-"${kver}" ; do
if [ -e "${BOOTPART}/${x}" ] ; then
echo "${BOOTPART}/${x}"
return 0
fi
done
return 1
}
load_image() {
if [ "${KNAME}" = "-" ] ; then
ebegin "Disabling kexec"
kexec -u
eend $?
return $?
fi
BOOTPART="${BOOTPART:-/boot}"
local img="$(image_path)" mounted=false initrdopt=
if [ -z "${img}" ] ; then
# If we cannot find our image, try mounting ${BOOTPART}
if ! grep -q " ${BOOTPART} " /proc/mounts ; then
ebegin "Mounting ${BOOTPART}"
mount "${BOOTPART}" && mounted=true
eend $? || return $?
img="$(image_path)"
fi
fi
if [ -z "${img}" ] ; then
eerror "No kernel image found in ${BOOTPART}!"
${mounted} && umount "${BOOTPART}"
return 1
fi
ebegin "Loading kernel image ${img} for kexec"
if [ -z "${ROOTPART}" ] ; then
ROOTPART="$(sed -n '/^[^ ]* \/ / s,^\([^ ]*\).*,\1,p' /etc/mtab)"
fi
if [ -z "${KPARAM}" ] ; then
KPARAM="$(sed -e 's/ /\n/g' /proc/cmdline | grep -v -e "^root=" | tr '\n' ' ')"
fi
# Use the default initrd if it exists and none other given
if [ -z "${INITRD}" -a -e "${BOOTPART}"/initrd ] ; then
INITRD="${BOOTPART}/initrd"
fi
if [ -e "${INITRD}" ] ; then
initrdopt="--initrd=${INITRD}"
fi
kexec -l "${img}" --append="root=${ROOTPART} ${KPARAM}" ${initrdopt}
local res=$?
${mounted} && umount "${BOOTPART}"
eend ${res}
return ${res}
}
start() {
[ "${LOAD_DURING_SHUTDOWN:-yes}" = "yes" ] && return 0
ebegin "Configuring kexec"
load_image
eend 0
}
stop() {
[ "${LOAD_DURING_SHUTDOWN:-yes}" != "yes" ] && return 0
ebegin "Configuring kexec"
if [ "${RC_SOFTLEVEL:-${SOFTLEVEL}}" != "reboot" ]; then
einfo "Not rebooting, so disabling"
kexec -u
return 0
fi
load_image
eend $?
}
|