155 lines
3.5 KiB
Bash
155 lines
3.5 KiB
Bash
#! /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.
|
|
#
|
|
# chkconfig: - 20 80
|
|
#
|
|
# Author: Jeff Moyer <jmoyer@redhat.com>
|
|
|
|
|
|
# Source function library.
|
|
. /etc/init.d/functions
|
|
|
|
KEXEC=/sbin/kexec
|
|
|
|
# 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=""
|
|
KDUMP_CONFIG_FILE="/etc/kdump.conf"
|
|
|
|
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
|
|
}
|
|
|
|
function check_config()
|
|
{
|
|
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
|
|
echo -n "No kdump kernel image found."; warning; echo
|
|
echo "Tried to locate ${kdump_kernel}"
|
|
exit 0
|
|
fi
|
|
|
|
if [ ! -f $kdump_initrd ]; then
|
|
echo -n "No kdump initial ramdisk found."; warning; echo
|
|
echo "Tried to locate ${kdump_initrd}"
|
|
return 1
|
|
fi
|
|
|
|
#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()
|
|
{
|
|
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'`
|
|
KDUMP_COMMANDLINE="${KDUMP_COMMANDLINE} irqpoll"
|
|
fi
|
|
|
|
$KEXEC $KEXEC_ARGS $standard_kexec_args \
|
|
--command-line="$KDUMP_COMMANDLINE" \
|
|
--initrd=$kdump_initrd $kdump_kernel
|
|
|
|
if [ $? == 0 ]; then
|
|
touch /var/run/kdump.status
|
|
fi
|
|
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
if [ -f /proc/vmcore ]; then
|
|
save_core
|
|
reboot
|
|
else
|
|
#TODO check raw partition for core dump image
|
|
check_config
|
|
load_kdump
|
|
fi
|
|
;;
|
|
stop)
|
|
$KEXEC -p -u
|
|
rm -f /var/run/kdump.status
|
|
;;
|
|
status)
|
|
if [ -a /var/run/kdump.status ]; then
|
|
echo "Kdump is operational"
|
|
else
|
|
echo "Kdump is not operational"
|
|
fi
|
|
;;
|
|
restart)
|
|
$KEXEC -p -u
|
|
rm -f /var/run/kdump.status
|
|
check_config
|
|
load_kdump
|
|
;;
|
|
condrestart)
|
|
;;
|
|
*)
|
|
echo $"Usage: $0 {start|stop|status|restart}"
|
|
exit 1
|
|
esac
|
|
|
|
exit $?
|