Re: [RFC] Debian mkinitrd patch for saving kdump - take2
On Wed, Aug 17, 2005 at 03:56:09PM +0530, Rachita Kothiyal wrote:
> Hi Jeff,
>
> As Vivek discussed with you in OLS regarding saving dump images
> from initrd, I have come up with an initial patch to mkinitrd on
> Debian unstable. This modifies the mkinitrd script to generate a
> custom initrd for dump capture kernel aka second kernel. This can
> help in saving the kdump memory image to the specified device
> and filesystem before mounting root filesystem.
>
> This is quite a crude patch just to convey the approach and has some
> things in the todo list. As of now it assumes that the dump device
> (disk partition) uses the same modules as the root device.
>
> ToDo:
> 1. Refine the script by providing better error handling
> 2. Automatically detecting filesystem for the dump device, if possible.
> 3. Finding required modules for accessing the dump device.
> 4. Network based dump device
>
> Usage:
> mkinitrd -k -o <destination> -c <dump_dev> -f <dump_dev_fs> kernel_version
>
> Example:
> mkinitrd -k -o /boot/initrd-capture-kernel.img -c /dev/hda7 -f ext2 2.6.13-rc5
>
In this attempt, I have tried to provide better error handling and also
handle the module loading required for accessing the dump device.
Please let me know your comments.
Thanks
Rachita
--- ../../mkinitrd-orig 2005-08-16 16:13:34.000000000 +0530
+++ ../../mkinitrd-mod/mkinitrd-8.18 2005-08-22 19:35:27.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
@@ -1122,6 +1124,15 @@ gendir() {
} >&3
[ -z "$ROOT" ] || probe
+ if [ $dump_enable -eq 1 ]; then
+ root_maj=$(ls -l $device | cut -d " " -f 6 | cut -d "," -f 1)
+ dump_maj=$(ls -l $dump_dev | cut -d " " -f 6 | cut -d "," -f 1)
+ dump_min=$(ls -l $dump_dev | cut -d " " -f 7)
+
+ if [ $root_maj -ne $dump_maj ]; then
+ getroot $dump_dev
+ fi
+ fi
exec 3>&- 4>&- 5>&- 6>&-
mkdir initrd
@@ -1206,6 +1217,7 @@ gendir() {
/bin/mount /bin/umount \
/sbin/pivot_root /bin/cat /bin/mknod \
/usr/sbin/chroot /bin/uname \
+ $([ $dump_enable -eq 1 ] && find /bin /sbin -name dd && find /bin /sbin -name reboot) \
`command -v stat` $readlink \
`cat "$@" exe`
do
@@ -1277,10 +1289,15 @@ 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 `[ $dump_enable -eq 1 ] && echo 'dump'`
> etc/mtab
+ if [ $dump_enable -eq 1 -a ! -b "${dump_dev#/}" ]; then
+ 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
@@ -1299,15 +1316,28 @@ gendir() {
fi
INITRDDIR=$dir/initrd MODULEDIR=$MODULEDIR VERSION=$VERSION \
run-parts "$CONFDIR"/scripts
+
+ if [ $dump_enable -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=""
+dump_enable=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"
@@ -1330,6 +1360,12 @@ while getopts "d:km:o:r:" flag; do
r)
croot=$OPTARG
;;
+ c)
+ dump_dev=$OPTARG
+ ;;
+ f)
+ dump_fs=$OPTARG
+ ;;
*)
usage
;;
@@ -1341,6 +1377,20 @@ if ! [ $out ] || [ $# -gt 1 ]; then
usage
fi
+if [ -z "$dump_dev" -a -z "$dump_fs" ]; then
+ dump_enable=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
+ dump_enable=1
+fi
+
VERSION=$1
[ $# -gt 0 ] || unset VERSION
case $VERSION in
Reply to: