[PATCH 1/2] Debian mkinitrd: initrd for automatically saving kdump
The following patch implements the feature to generate a special
initrd to automatically save the kdump.
--- mkinitrd.orig 2005-08-24 18:21:04.000000000 +0530
+++ mkinitrd 2005-08-24 18:22:17.000000000 +0530
@@ -99,6 +99,8 @@ Options:
-m command Set the command to make an initrd image.
-o outfile Write to outfile.
-r root Override ROOT setting in mkinitrd.conf.
+ -c dump_device Copy dump to this device
+ -f dump_dev_fs Filesystem on the dump device
See mkinitrd(8) for further details.
EOF
@@ -1121,8 +1123,11 @@ gendir() {
echo 'unix 2> /dev/null'
echo '. swsusp 2> /dev/null' >&7
} >&3
- [ -z "$ROOT" ] || probe
+ [ -z "$ROOT" -o $kdump_capture -eq 1 ] || probe
+ if [ $kdump_capture -eq 1 ]; then
+ getroot $dump_dev
+ fi
exec 3>&- 4>&- 5>&- 6>&-
mkdir initrd
@@ -1207,6 +1212,7 @@ gendir() {
/bin/mount /bin/umount \
/sbin/pivot_root /bin/cat /bin/mknod \
/usr/sbin/chroot /bin/uname \
+ $([ $kdump_capture -eq 1 ] && find /bin /sbin -name dd && find /bin /sbin -name reboot) \
`command -v stat` $readlink \
`cat "$@" exe`
do
@@ -1279,10 +1285,17 @@ gendir() {
esac
cd initrd
- mkdir -p dev2 devfs etc keyscripts mnt proc scripts sys tmp var
+ mkdir -p dev2 devfs etc keyscripts mnt proc scripts sys tmp var `[ $kdump_capture -eq 1 ] && echo 'dump'`
> etc/mtab
+ if [ $kdump_capture -eq 1 -a ! -b "${dump_dev#/}" ]; then
+ dump_maj=$(ls -l $dump_dev | cut -d " " -f 6 | cut -d "," -f 1)
+ dump_min=$(ls -l $dump_dev | cut -d " " -f 7)
+ dev_type=$(ls -l $dump_dev | cut -c 1)
+ mknod "${dump_dev#/}" $dev_type $dump_maj $dump_min
+ DEVLINKS="$DEVLINKS ${dump_dev#/dev/}"
+ fi
devices=
for i in \
cciss ida ide scsi md mapper $DEVLINKS
@@ -1301,15 +1314,28 @@ gendir() {
fi
INITRDDIR=$dir/initrd MODULEDIR=$MODULEDIR VERSION=$VERSION \
run-parts "$CONFDIR"/scripts
+
+ if [ $kdump_capture -eq 1 ]; then
+ echo "mount -t $dump_fs $dump_dev /dump
+echo Copying the dump
+dd if=/proc/vmcore of=/dump/dumpfile
+umount /dump
+echo Rebooting the system
+reboot -f" >> script
+ fi
}
ORIGDIR=`pwd`
PROG="$0"
+dump_dev=""
+dump_fs=""
+kdump_capture=0
+
CONFDIR=/etc/mkinitrd
unset keep croot cmkimage out || :
-while getopts "d:km:o:r:" flag; do
+while getopts "d:km:o:r:c:f:" flag; do
case $flag in
d)
CONFDIR="$OPTARG"
@@ -1332,6 +1358,12 @@ while getopts "d:km:o:r:" flag; do
r)
croot=$OPTARG
;;
+ c)
+ dump_dev=$OPTARG
+ ;;
+ f)
+ dump_fs=$OPTARG
+ ;;
*)
usage
;;
@@ -1343,6 +1375,20 @@ if ! [ $out ] || [ $# -gt 1 ]; then
usage
fi
+if [ -z "$dump_dev" -a -z "$dump_fs" ]; then
+ kdump_capture=0
+elif [ -z "$dump_dev" -a ! -z "$dump_fs" ]; then
+ echo 'Please specify a dump device'
+ usage
+ exit 1
+elif [ ! -z "$dump_dev" -a -z "$dump_fs" ]; then
+ echo 'Please specify a filesystem for the dump device'
+ usage
+ exit 1
+else
+ kdump_capture=1
+fi
+
VERSION=$1
[ $# -gt 0 ] || unset VERSION
case $VERSION in
Reply to: