#!/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

# Do NOT exit the script after this point, or the system will start
# booting inside the crash kernel.

. ./scripts/functions

# Make sure makedumpfile assumptions are satisfied.
while ! test -e "$INFO"; do
	panic "kdump: Missing $INFO"
done
while ! test -x "$MAKEDUMPFILE"; do
	panic "kdump: Missing $MAKEDUMPFILE"
done

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 -E -d 31 -i $INFO $VMCORE $CRASHFILE > $LOG 2>&1 || \
	rm -f $CRASHFILE

chmod 400 $CRASHFILE

mount $rootmnt -o remount,ro
reboot

log_end_msg
