5
# Required-Stop: $local_fs $remote_fs kexec
9
# Short-Description: Load kernel image with kexec
13
PATH=/sbin:/bin:/usr/sbin:/usr/bin
14
NOKEXECFILE=/tmp/no-kexec-reboot
16
. /lib/lsb/init-functions
18
test -r /etc/default/kexec && . /etc/default/kexec
20
process_grub_entry() {
22
while read command args; do
23
if [ "$command" = "linux" ]; then
24
echo "$args" | while read kernel append; do
25
echo KERNEL_IMAGE=\"${prefix}${kernel}\"
26
echo APPEND=\"${append}\"
28
elif [ "$command" = "initrd" ]; then
29
initrd_image=${prefix}${args}
32
echo INITRD=\"$initrd_image\"
36
test -f /boot/grub/grub.cfg || return
38
mountpoint -q /boot && prefix=/boot || prefix=
39
data=$(cat /boot/grub/grub.cfg)
41
default=$(echo "$data" | awk '/^set default/ {print $2}' | cut -d'"' -f2)
42
if [ "$default" = '${saved_entry}' ]; then
43
default=$(sed -ne 's/^saved_entry=//p' /boot/grub/grubenv)
45
if [ -z "$default" ]; then
48
start_offset=$((default + 1))
49
end_offset=$((default + 2))
51
# grub entries start with "menuentry" commands. Get the line
52
# numbers that surround the first entry
53
offsets=$(echo "$data" | grep -n '^[[:space:]]*menuentry[[:space:]]' | cut -d: -f1)
54
begin=$(echo "$offsets" | tail -n+$start_offset | head -n1)
55
end=$(echo "$offsets" | tail -n+$end_offset | head -n1)
57
# If this is the last entry, we need to read to the end of the file
58
# or to the end of boot entry section
59
if [ -z "$end" ]; then
60
numlines=$(echo "$data" | tail --lines=+$begin | grep -n "^### END" | head -1 | cut -d: -f1)
61
end=$((begin + numlines - 1))
64
length=$((end - begin))
65
entry=$(echo "$data" | tail -n+$begin | head -n$length)
66
eval $(echo "$entry" | process_grub_entry)
70
test "$LOAD_KEXEC" = "true" || exit 0
71
test -x /sbin/kexec || exit 0
72
test "x`cat /sys/kernel/kexec_loaded`y" = "x1y" && exit 0
74
if [ -f $NOKEXECFILE ]
76
/bin/rm -f $NOKEXECFILE
80
test "$USE_GRUB_CONFIG" = "true" && get_grub_kernel
84
test -z "$REAL_APPEND" && REAL_APPEND="`cat /proc/cmdline`"
85
log_action_begin_msg "Loading new kernel image into memory"
88
/sbin/kexec -l "$KERNEL_IMAGE" --append="$REAL_APPEND"
90
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$REAL_APPEND"
99
restart|reload|force-reload)
100
echo "Error: argument '$1' not supported" >&2
107
echo "Usage: $0 start|stop" >&2