2011-07-28 14:50:43 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. /lib/dracut-lib.sh
|
|
|
|
|
|
|
|
set -x
|
|
|
|
KDUMP_PATH="/var/crash"
|
|
|
|
CORE_COLLECTOR="makedumpfile -d 31 -c"
|
|
|
|
DEFAULT_ACTION="reboot -f"
|
|
|
|
DATEDIR=`date +%d.%m.%y-%T`
|
|
|
|
DUMP_INSTRUCTION=""
|
|
|
|
|
|
|
|
do_default_action()
|
|
|
|
{
|
|
|
|
wait_for_loginit
|
|
|
|
$DEFAULT_ACTION
|
|
|
|
}
|
|
|
|
|
2011-08-01 12:01:31 +00:00
|
|
|
add_dump_code()
|
2011-07-28 14:50:43 +00:00
|
|
|
{
|
|
|
|
if [ -z "$DUMP_INSTRUCTION" ]
|
|
|
|
then
|
|
|
|
DUMP_INSTRUCTION="$1"
|
|
|
|
else
|
|
|
|
DUMP_INSTRUCTION="$DUMP_INSTRUCTION && $1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-08-01 14:53:00 +00:00
|
|
|
add_to_fstab()
|
|
|
|
{
|
|
|
|
local _mp
|
|
|
|
while read dev mp fs opts rest; do
|
|
|
|
if [ "$dev" = "$1" ]; then
|
|
|
|
_mp=$NEWROOT$mp
|
|
|
|
echo "$dev $NEWROOT$mp $fs ${opts},ro $rest"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done < "$NEWROOT/etc/fstab" >> /etc/fstab
|
|
|
|
echo "$_mp"
|
|
|
|
}
|
|
|
|
|
2011-08-01 12:01:31 +00:00
|
|
|
dump_localfs()
|
|
|
|
{
|
2011-08-01 14:53:00 +00:00
|
|
|
local _mp=`add_to_fstab $1`
|
|
|
|
mount $_mp || return 1
|
|
|
|
mkdir -p $_mp/$KDUMP_PATH/$DATEDIR
|
|
|
|
$CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$DATEDIR/vmcore || return 1
|
2011-08-01 12:01:31 +00:00
|
|
|
umount /mnt || return 1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_raw()
|
|
|
|
{
|
|
|
|
CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e's/\(^makedumpfile\)\(.*$\)/\1 -F \2/'`
|
|
|
|
$CORE_COLLECTOR /proc/vmcore | dd of=$1 bs=512 || return 1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-07-28 14:50:43 +00:00
|
|
|
dump_rootfs()
|
|
|
|
{
|
|
|
|
mount -o remount,rw $NEWROOT/ || return 1
|
|
|
|
mkdir -p $NEWROOT/$KDUMP_PATH/$DATEDIR
|
|
|
|
$CORE_COLLECTOR /proc/vmcore $NEWROOT/$KDUMP_PATH/$DATEDIR/vmcore || return 1
|
|
|
|
sync
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_nfs()
|
|
|
|
{
|
2011-08-01 12:01:31 +00:00
|
|
|
mount -o remount,rw $NEWROOT/ || return 1
|
|
|
|
[ -d $NEWROOT/mnt ] || mkdir -p $NEWROOT/mnt
|
2011-07-28 14:50:43 +00:00
|
|
|
mount -o nolock -o tcp -t nfs $1 $NEWROOT/mnt/
|
|
|
|
mkdir -p $NEWROOT/mnt/$KDUMP_PATH/$DATEDIR || return 1
|
|
|
|
$CORE_COLLECTOR /proc/vmcore $NEWROOT/mnt/$KDUMP_PATH/$DATEDIR/vmcore || return 1
|
|
|
|
umount $NEWROOT/mnt/ || return 1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_ssh()
|
|
|
|
{
|
|
|
|
ssh -q -o BatchMode=yes -o StrictHostKeyChecking=yes $1 mkdir -p $KDUMP_PATH/$DATEDIR || return 1
|
|
|
|
scp -q -o BatchMode=yes -o StrictHostKeyChecking=yes /proc/vmcore "$1:$KDUMP_PATH/$DATEDIR" || return 1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-08-01 12:01:31 +00:00
|
|
|
to_dev_name()
|
|
|
|
{
|
2011-08-01 14:53:00 +00:00
|
|
|
local dev="$1"
|
|
|
|
|
|
|
|
case "$dev" in
|
|
|
|
UUID=*)
|
|
|
|
dev=`blkid -U "${dev#UUID=}"`
|
|
|
|
;;
|
|
|
|
LABEL=*)
|
|
|
|
dev=`blkid -L "${dev#LABEL=}"`
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo $dev
|
2011-08-01 12:01:31 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 14:50:43 +00:00
|
|
|
read_kdump_conf()
|
|
|
|
{
|
|
|
|
local conf_file="/etc/kdump.conf"
|
|
|
|
if [ -f "$conf_file" ]; then
|
|
|
|
while read config_opt config_val;
|
|
|
|
do
|
|
|
|
case "$config_opt" in
|
2011-08-01 12:01:31 +00:00
|
|
|
ext[234]|xfs|btrfs|minix)
|
2011-08-01 14:53:00 +00:00
|
|
|
add_dump_code "dump_localfs "$(to_dev_name $config_val)" || do_default_action"
|
2011-08-01 12:01:31 +00:00
|
|
|
;;
|
|
|
|
raw)
|
|
|
|
add_dump_code "dump_raw $config_val || do_default_action"
|
|
|
|
;;
|
2011-07-28 14:50:43 +00:00
|
|
|
path)
|
|
|
|
KDUMP_PATH="$config_val"
|
|
|
|
;;
|
|
|
|
core_collector)
|
|
|
|
CORE_COLLECTOR="$config_val"
|
|
|
|
;;
|
|
|
|
net)
|
|
|
|
if [ -n "$(echo $config_val | grep @)" ]
|
|
|
|
then
|
2011-08-01 12:01:31 +00:00
|
|
|
add_dump_code "dump_ssh $config_val || do_default_action"
|
2011-07-28 14:50:43 +00:00
|
|
|
else
|
2011-08-01 12:01:31 +00:00
|
|
|
add_dump_code "dump_nfs $config_val || do_default_action"
|
2011-07-28 14:50:43 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
default)
|
|
|
|
case $config_val in
|
|
|
|
shell)
|
|
|
|
DEFAULT_ACTION="sh -i -l"
|
|
|
|
;;
|
|
|
|
reboot)
|
|
|
|
DEFAULT_ACTION="reboot -f"
|
|
|
|
;;
|
|
|
|
halt)
|
|
|
|
DEFAULT_ACTION="halt -f"
|
|
|
|
;;
|
|
|
|
poweroff)
|
|
|
|
DEFAULT_ACTION="poweroff -f"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done < $conf_file
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
read_kdump_conf
|
|
|
|
|
|
|
|
if [ -n "$DUMP_INSTRUCTION" ]
|
|
|
|
then
|
|
|
|
eval "$DUMP_INSTRUCTION"
|
|
|
|
else
|
|
|
|
dump_rootfs
|
|
|
|
do_default_action
|
|
|
|
fi
|
|
|
|
|
|
|
|
|