--- mkinitrd.orig 2005-09-22 01:59:25.393789168 -0700 +++ mkinitrd 2005-09-22 02:15:26.412692088 -0700 @@ -60,6 +60,9 @@ usage() { Description Table) to initrd. This replaces the DSDT of the BIOS. Defaults to the ACPI_DSDT variable in /etc/sysconfig/kernel. + -v dump_dev Dump device for kexec based crash dump + -f dump_fs Filesystem on the dump device for kexec based + crashdump -S Load policy file for SELinux if exist. root_dir: The directory the root partition is mounted on. Defaults to "/". @@ -145,7 +148,7 @@ case "$(uname -m)" in ;; esac -while getopts :hk:i:m:b:d:s:St:D:I:a: a ; do +while getopts :hk:i:m:b:d:s:St:D:I:a:v:f: a ; do case $a in \:|\?) case $OPTARG in k) echo "-k requires kernel list parameter" @@ -168,6 +171,10 @@ while getopts :hk:i:m:b:d:s:St:D:I:a: a ;; a) echo "-a requires a DSDT parameter" ;; + v) echo "-v requires a dump device parameter" + ;; + f) echo "-f requires a filesystem parameter" + ;; *) echo "Unknown option: -$OPTARG" echo "Try mkinitrd -h" ;; @@ -201,6 +208,10 @@ while getopts :hk:i:m:b:d:s:St:D:I:a: a ;; a) acpi_dsdt="$OPTARG" ;; + v) dump_dev="$OPTARG" + ;; + f) dump_fs="$OPTARG" + ;; S) use_selinux=1 ;; h) usage @@ -260,6 +271,21 @@ if [ -z "$kernel_images" -o -z "$initrd_ 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 + #this will save space + use_static_binaries="" +fi # Check which shell and insmod binaries to use in initrd. [ -x $root_dir/bin/ash ] \ && initrd_shell_dynamic=$root_dir/bin/ash @@ -296,6 +322,19 @@ fi # FIXME agruen: Is is really necessary to fall back to /bin/ash.static # and /sbin/initrd.static outside the $root_dir? +if [ $kdump_capture -eq 1 ];then + if [ -x $root_dir/bin/dd ]; then + initrd_dd=$root_dir/bin/dd + else + echo "Could not find dd. Aborting" + fi + if [ -x $root_dir/sbin/reboot ]; then + initrd_reboot=$root_dir/sbin/$(readlink /sbin/reboot) + else + echo "Could not find reboot. Aborting" + fi +fi + # maximum initrd size image_blocks=40960 image_inodes=2048 @@ -1126,9 +1165,17 @@ mkinitrd_kernel() { rmdir $tmp_mnt/lost+found mkdir -p $tmp_mnt/{sbin,etc,bin,dev} mkdir -p $tmp_mnt/dev/shm + [ $kdump_capture -eq 1 ] && mkdir -p $tmp_mnt/dump initrd_devices=$(echo dev/{zero,null,ram0,ram1,ram2,ram,ramdisk} \ dev/{console,md0}) + if [ $kdump_capture -eq 1 -a ! -b "$tmp_mnt$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 "$tmp_mnt$dump_dev" $dev_type $dump_maj $dump_min + fi + # Create a dummy /etc/mtab for mount/umount echo -n > $tmp_mnt/etc/mtab @@ -1158,6 +1205,13 @@ mkinitrd_kernel() { cp_bin $initrd_insmod.old $tmp_mnt/sbin/insmod.old 2>/dev/null fi + if [ -n $initrd_dd ]; then + cp_bin $initrd_dd $tmp_mnt/sbin/dd 2>/dev/null + fi + + if [ -n $initrd_reboot ]; then + cp_bin $initrd_reboot $tmp_mnt/sbin/reboot 2>/dev/null + fi # SELinux: Binary policy file and load_policy utility for loading it. if [ -n "$use_selinux" ] ; then if [ -f $root_dir/etc/security/selinux/policy.15 -a \ @@ -1512,7 +1566,9 @@ mkinitrd_kernel() { fi # Check for IDE modules, might change use_udev + if [ $kdump_capture -eq 0 ] || [ $kdump_capture -eq 1 -a "$(echo $dump_dev | cut -d/ -f3 | cut -c1-2)" = "hd" ]; then check_ide_modules $root_dir/lib/modules/$kernel_version + fi resolved_modules="$(resolve_modules $kernel_version $modules)" @@ -1520,6 +1576,7 @@ mkinitrd_kernel() { # for kernels which don't have this built in. In that case, assume # that the root file system is on a SCSI device, and also include # sd_mod. + if [ $kdump_capture -eq 0 ] || [ $kdump_capture -eq 1 -a "$(echo $dump_dev | cut -d/ -f3 | cut -c1-2)" = "sd" ];then local have_scsi have_sd case "$resolved_modules" in */scsi_mod.*) have_scsi=1 @@ -1535,6 +1592,7 @@ mkinitrd_kernel() { resolved_modules="$(resolve_modules $kernel_version $modules)" fi + fi # Copy the modules to the initrd echo -ne "Modules:\t" initrd_is_using_modules= @@ -1746,6 +1804,18 @@ mkinitrd_kernel() { ;; esac + if [ $kdump_capture -eq 1 ]; then + cat_linuxrc <<-EOF + | + |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 + EOF + fi + # Check for multipathing cat_linuxrc <<-'EOF' |for o in $(cat /proc/cmdline); do