2005-09-23 21:04:31 +00:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
#
|
|
|
|
# kdump
|
|
|
|
#
|
|
|
|
# Description: The kdump init script provides the support necessary for
|
|
|
|
# loading a kdump kernel into memory at system bootup time,
|
|
|
|
# and for copying away a vmcore at system panic time.
|
|
|
|
#
|
|
|
|
# Copyright 2005 Red Hat, Inc.
|
|
|
|
#
|
2006-09-28 16:16:04 +00:00
|
|
|
# chkconfig: 2345 20 80
|
2005-09-23 21:04:31 +00:00
|
|
|
#
|
|
|
|
# Author: Jeff Moyer <jmoyer@redhat.com>
|
|
|
|
|
|
|
|
|
|
|
|
# Source function library.
|
|
|
|
. /etc/init.d/functions
|
|
|
|
|
2006-03-07 18:50:02 +00:00
|
|
|
KEXEC=/sbin/kexec
|
2005-09-23 21:04:31 +00:00
|
|
|
|
|
|
|
# Will be different for ia64, for example. For now, that architecture isn't
|
|
|
|
# supported. Code needs to be added here when we do.
|
|
|
|
BOOTDIR="/boot"
|
|
|
|
|
|
|
|
KDUMP_KERNELVER=""
|
|
|
|
KDUMP_COMMANDLINE=""
|
|
|
|
KEXEC_ARGS=""
|
2006-07-27 13:08:21 +00:00
|
|
|
KDUMP_CONFIG_FILE="/etc/kdump.conf"
|
2005-09-23 21:04:31 +00:00
|
|
|
|
|
|
|
standard_kexec_args="-p --args-linux"
|
|
|
|
|
|
|
|
if [ -f /etc/sysconfig/kdump ]; then
|
|
|
|
. /etc/sysconfig/kdump
|
|
|
|
fi
|
|
|
|
|
|
|
|
function save_core()
|
|
|
|
{
|
|
|
|
coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
|
|
|
|
|
|
|
|
mkdir -p $coredir
|
|
|
|
cp /proc/vmcore $coredir/vmcore
|
|
|
|
}
|
|
|
|
|
2006-07-27 13:08:21 +00:00
|
|
|
function check_config()
|
2005-09-23 21:04:31 +00:00
|
|
|
{
|
|
|
|
if [ -z "$KDUMP_KERNELVER" ]; then
|
|
|
|
local running_kernel=`uname -r`
|
|
|
|
|
|
|
|
kdump_kver=`echo $running_kernel | sed 's/smp//g'`
|
|
|
|
kdump_kver="${kdump_kver}kdump"
|
|
|
|
else
|
|
|
|
kdump_kver=$KDUMP_KERNELVER
|
|
|
|
fi
|
|
|
|
|
|
|
|
kdump_kernel="${BOOTDIR}/vmlinux-${kdump_kver}"
|
|
|
|
kdump_initrd="${BOOTDIR}/initrd-${kdump_kver}.img"
|
|
|
|
|
|
|
|
if [ ! -f $kdump_kernel ]; then
|
2005-11-22 21:52:53 +00:00
|
|
|
echo -n "No kdump kernel image found."; warning; echo
|
2006-08-15 15:16:07 +00:00
|
|
|
echo "Tried to locate ${kdump_kernel}"
|
2005-11-22 21:52:53 +00:00
|
|
|
exit 0
|
2005-09-23 21:04:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $kdump_initrd ]; then
|
2006-08-15 15:16:07 +00:00
|
|
|
echo -n "No kdump initial ramdisk found."; warning; echo
|
2005-09-23 21:04:31 +00:00
|
|
|
echo "Tried to locate ${kdump_initrd}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2006-07-27 13:08:21 +00:00
|
|
|
#check to see if config file has been modified after
|
|
|
|
#last build of the image file
|
|
|
|
config_time=0
|
|
|
|
if [ -f $KDUMP_CONFIG_FILE ]; then
|
|
|
|
config_time=`stat -c "%Y" $KDUMP_CONFIG_FILE`
|
|
|
|
fi
|
|
|
|
kernel_time=`stat -c "%Y" $kdump_kernel`
|
|
|
|
image_time=`stat -c "%Y" $kdump_initrd`
|
|
|
|
|
|
|
|
if [ "$config_time" -gt "$image_time" ] ||
|
|
|
|
[ "$kernel_time" -gt "$image_time" ]; then
|
|
|
|
echo "Detected $KDUMP_CONFIG_FILE or $kdump_kernel change"
|
|
|
|
echo "Rebuilding $kdump_initrd"
|
|
|
|
/sbin/mkdumprd -d -f $kdump_initrd $kdump_kver
|
|
|
|
fi
|
|
|
|
|
|
|
|
#hack until we stop making initrd for kdump during rpm install
|
|
|
|
#allow initrd 120 seconds to be created before considering it new
|
|
|
|
module_time=`stat -c "%Y" /lib/modules/${kdump_kver}`
|
|
|
|
let module_time=module_time+120
|
|
|
|
if [ ! "$image_time" -gt "$module_time" ]; then
|
|
|
|
echo "Detected initial rpm install"
|
|
|
|
echo "Rebuilding $kdump_initrd"
|
|
|
|
/sbin/mkdumprd -d -f $kdump_initrd $kdump_kver
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Load the kdump kerel specified in /etc/sysconfig/kdump
|
|
|
|
# If none is specified, try to load a kdump kernel with the same version
|
|
|
|
# as the currently running kernel.
|
|
|
|
function load_kdump()
|
|
|
|
{
|
2005-09-23 21:04:31 +00:00
|
|
|
if [ -z "$KDUMP_COMMANDLINE" ]; then
|
|
|
|
KDUMP_COMMANDLINE=`cat /proc/cmdline`
|
|
|
|
KDUMP_COMMANDLINE=`echo $KDUMP_COMMANDLINE | sed -e 's/crashkernel=[0-9]\+M@[0-9]\+M//g'`
|
2006-02-17 23:58:33 +00:00
|
|
|
KDUMP_COMMANDLINE="${KDUMP_COMMANDLINE} irqpoll"
|
2005-09-23 21:04:31 +00:00
|
|
|
fi
|
|
|
|
|
2006-02-27 09:19:03 +00:00
|
|
|
$KEXEC $KEXEC_ARGS $standard_kexec_args \
|
2006-02-22 20:59:15 +00:00
|
|
|
--command-line="$KDUMP_COMMANDLINE" \
|
2005-09-23 21:04:31 +00:00
|
|
|
--initrd=$kdump_initrd $kdump_kernel
|
2006-08-15 15:16:07 +00:00
|
|
|
|
|
|
|
if [ $? == 0 ]; then
|
|
|
|
touch /var/run/kdump.status
|
|
|
|
fi
|
|
|
|
|
2005-09-23 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
if [ -f /proc/vmcore ]; then
|
|
|
|
save_core
|
|
|
|
reboot
|
|
|
|
else
|
2006-07-27 13:08:21 +00:00
|
|
|
#TODO check raw partition for core dump image
|
|
|
|
check_config
|
2005-09-23 21:04:31 +00:00
|
|
|
load_kdump
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
stop)
|
2006-03-02 09:18:31 +00:00
|
|
|
$KEXEC -p -u
|
2006-08-15 15:16:07 +00:00
|
|
|
rm -f /var/run/kdump.status
|
2005-09-23 21:04:31 +00:00
|
|
|
;;
|
|
|
|
status)
|
2006-08-15 15:16:07 +00:00
|
|
|
if [ -a /var/run/kdump.status ]; then
|
|
|
|
echo "Kdump is operational"
|
|
|
|
else
|
|
|
|
echo "Kdump is not operational"
|
|
|
|
fi
|
2005-09-23 21:04:31 +00:00
|
|
|
;;
|
|
|
|
restart)
|
2006-03-02 09:18:31 +00:00
|
|
|
$KEXEC -p -u
|
2006-08-15 15:16:07 +00:00
|
|
|
rm -f /var/run/kdump.status
|
2006-07-27 13:08:21 +00:00
|
|
|
check_config
|
2006-02-17 23:58:33 +00:00
|
|
|
load_kdump
|
2005-09-23 21:04:31 +00:00
|
|
|
;;
|
|
|
|
condrestart)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo $"Usage: $0 {start|stop|status|restart}"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $?
|