#!/bin/sh

PREREQ=""
prereqs()
{
	echo "$PREREQ"
}
case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
esac

KVER="`uname -r`"
INFO="$rootmnt/boot/vmcoreinfo-$KVER"
CRASHFILE="$rootmnt/var/crash/vmcore"
MAKEDUMPFILE="$rootmnt/usr/bin/makedumpfile"
LOG="$rootmnt/var/crash/vmcore.log"
VMCORE="/proc/vmcore"

# Check that this is a kexec kernel.
grep -q kdump_needed /proc/cmdline || exit 0

# Make sure makedumpfile assumptions are satisfied.
test -e $INFO || exit 0
test -x $MAKEDUMPFILE || exit 0

. ./scripts/functions

log_begin_msg "Saving vmcore from kernel crash"

mount $rootmnt -o remount,rw

# Delete it if the copy fails, mainly to keep from filling up filesystems
# by accident.
#
$MAKEDUMPFILE -d 31 -i $INFO $VMCORE $CRASHFILE > $LOG 2>&1 || \
	rm -f $CRASHFILE

chmod 400 $CRASHFILE

mount $rootmnt -o remount,ro
reboot

log_end_msg
