further updates to mkdumprd for scp dumping with busybox

This commit is contained in:
Neil Horman 2006-09-22 19:09:02 +00:00
parent 9ac14dd3ed
commit 31a04fb720

124
mkdumprd
View File

@ -1,7 +1,7 @@
#!/bin/bash --norc
# vim:sts=4:sw=4:ts=8:et
# mkinitrd
# mkdumprd
#
# Copyright 2005 Red Hat, Inc.
#
@ -24,6 +24,7 @@
# Bill Nottingham <notting@redhat.com>
# Guillaume Cottenceau <gc@mandrakesoft.com>
# Peter Jones <pjones@redhat.com>
# Neil Horman <nhorman@redhat.com>
umask 0022
@ -386,7 +387,7 @@ handlelvordev() {
handlenetdev() {
local dev=$1
local rip=$2
source /etc/sysconfig/network
if [ ! -f /etc/sysconfig/network-scripts/ifcfg-$dev ]; then
error "unable to find network device configuration for $dev"
@ -395,8 +396,15 @@ handlenetdev() {
[ -n "$BOOTPROTO" ] || error "bootproto not specified for $dev"
findnetdriver $dev
[ -z "$IPADDR" ] && IPADDR=`ip addr show dev $dev scope global | grep inet | awk '{print $2}' | cut -d/ -f1`
[ -n "$IPADDR" ] && IPSTR="$IPSTR --ip $IPADDR"
if [ -z "$NETMASK" ]; then
IPPREFIX=`ip addr show dev $dev scope global | grep inet | awk '{print $2}'`
NETMASK=`ipcalc --netmask $IPPREFIX | cut -d= -f2`
fi
[ -n "$NETMASK" ] && IPSTR="$IPSTR --netmask $NETMASK"
[ -z "$GATEWAY" ] && GATEWAY=`ip route get to $rip | awk '/.*via.*/{print$3}'`
[ -z "$GATEWAY" ] && GATEWAY=`ip route list | grep default | awk '/.*via.*/{print$3}'`
[ -n "$GATEWAY" ] && IPSTR="$IPSTR --gateway $GATEWAY"
[ -n "$ETHTOOL_OPTS" ] && IPSTR="$IPSTR --ethtool \"$ETHTOOL_OPTS\""
[ -n "$MTU" ] && IPSTR="$IPSTR --mtu $MTU"
@ -420,7 +428,19 @@ handlenetdev() {
dev=$KDUMP_IFC
fi
network="network --device $dev --bootproto $BOOTPROTO $IPSTR"
BUS_ID=`/sbin/ethtool -i $dev | grep bus-info`
cat >> $MNTIMAGE/etc/ifcfg-$dev << EOF
IPADDR=$IPADDR
NETMASK=$NETMASK
GATEWAY=$GATEWAY
ETHTOL_OPTS=$ETHTOOL_OPTS
MTU=$MTU
DNS1=$DNS1
DNS2=$DNS2
BOOTPROTO=$BOOTPROTO
BUS_ID="$BUS_ID"
EOF
}
while [ $# -gt 0 ]; do
@ -848,7 +868,8 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
netdev=`echo $netdev|awk '{print $3;}'|head -n 1`
#add the ethernet device to the list of modules
handlenetdev $netdev
mkdir -p $MNTIMAGE/etc
handlenetdev $netdev $rhost
#load nfs modules, if needed
echo $location | grep -v "@" > /dev/null && findmodule nfs
@ -902,6 +923,7 @@ mkdir -p $MNTIMAGE/proc
mkdir -p $MNTIMAGE/sys
mkdir -p $MNTIMAGE/sysroot
mkdir -p $MNTIMAGE/modules
mkdir -p $MNTIMAGE/usr/share/udhcpc
ln -s bin $MNTIMAGE/sbin
@ -941,6 +963,13 @@ EOF
chmod 755 $MNTIMAGE/bin/sh
cat >> $MNTIMAGE/usr/share/udhcpc/default.script << EOF
#!/bin/msh
EOF
chmod 755 $MNTIMAGE/usr/share/udhcpc/default.script
if [ -e /etc/fstab.sys ]; then
inst /etc/fstab.sys "$MNTIMAGE/etc/fstab.sys"
fi
@ -993,9 +1022,8 @@ if [ -n "$vg_list" ]; then
fi
echo -n >| $RCFILE
cemit << EOF
cat >> $MNTIMAGE/init << EOF
#!/bin/msh
mount -t proc /proc /proc
setquiet
echo Mounting proc filesystem
@ -1015,7 +1043,7 @@ mknod /dev/tty c 5 0
mknod /dev/console c 5 1
mknod /dev/ptmx c 5 2
mknod /dev/rtc c 10 135
mknod /dev/urandom c 1 9
EOF
if [ "$(uname -m)" == "ia64" ]; then
emit "mknod $MNTIMAGE/dev/efirtc c 10 136"
@ -1080,7 +1108,10 @@ emit " MINOR_END=\`echo \$MINOR_NUM 10 + p | dc\`"
emit " MINOR_START=\`echo \$MINOR_NUM 1 + p | dc\`"
emit " for j in \`seq \$MINOR_START 1 \$MINOR_END\`"
emit " do"
emit " mknod /dev/\$i\$j b \$MAJOR_NUM \$j"
emit " if [ ! -e /dev/\$i\$j ]"
emit " then"
emit " mknod /dev/\$i\$j b \$MAJOR_NUM \$j"
emit " fi"
emit " done"
emit "done"
@ -1113,13 +1144,16 @@ if [ -n "$vg_list" ]; then
emit "lvm vgscan --ignorelockingfailure --mknodes"
emit "echo Activating logical volumes"
emit "lvm vgchange -a y --ignorelockingfailure"
emit "for i in \`lvm lvs | awk '/Log.*/ { print \$1}'\`"
emit "DM_NUM=0"
emit "for i in \`lvm lvs | awk '{ if (NR > 1) print \$1}'\`"
emit "do"
emit " VGRP=\`lvm lvs | grep \$i | cut -d\" \" -f4\`"
emit " mkdir -p /dev/\$VGRP"
emit " if [ ! -e /dev/\$VGRP/\$i ]"
emit " then"
emit " ln -s /dev/mapper/\$VGRP-\$i /dev/\$VGRP/\$i"
emit " ln -s /dev/mapper/\$VGRP-\$i /dev/dm-\$DM_NUM"
emit " DM_NUM=\`echo \$DM_NUM 1 + p | dc\`"
emit " if [ -z \"\$noresume\" ]"
emit " then"
emit " /sbin/dmsetup resume /dev/mapper/\$VGRP-\$i"
@ -1135,12 +1169,13 @@ kdump_chk()
exit 1
}
emit "DATE=\`date +%Y-%M-%d-%T\`"
if [ -n "$KDUMP_CONFIG_FILE" ]; then
memtotal=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`
#timezone info for date which outputs YYYY-MM-DD-hh:mm
cp /etc/localtime $MNTIMAGE/etc/localtime
bin="/sbin/dmsetup /sbin/kcp /usr/bin/scp /usr/bin/ssh /sbin/kcp /sbin/ethtool /sbin/mdadm"
bin="/sbin/dmsetup /usr/bin/scp /usr/bin/ssh /sbin/ethtool /sbin/mdadm"
#ssh, scp require libraries that aren't found with ldd
lib=/lib && [ -d "/lib64" ] && lib=/lib64
k_extras="/$lib/libnss_compat.so.2 /$lib/libnss_files.so.2"
@ -1175,9 +1210,44 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
grep "^root" /etc/passwd > $MNTIMAGE/etc/passwd
# bring up the network
emit "echo Bring up network"
emit $network
emit "for i in \`ls /etc/ifcfg*\`"
emit "do"
emit " NETDEV=\`echo \$i | cut -d\"-\" -f2\`"
emit " echo activating \$NETDEV"
emit " REAL_DEV=\"\""
emit " #first source the config information"
emit " . /etc/ifcfg-\$NETDEV"
emit " #now search for the real device name"
emit " #based on bus id information"
emit " for i in \`ifconfig -a | awk '/.*Link encap.*/ {print \$1}'\`"
emit " do"
emit " if [ -z \"\$REAL_DEV\" ]"
emit " then"
emit " INFO=\`ethtool -i \$i | grep bus-info\`"
emit " if [ \"\$INFO\" == \"\$BUS_ID\" ]"
emit " then"
emit " REAL_DEV=\$i"
emit " fi"
emit " fi"
emit " done"
emit " ifconfig \$REAL_DEV up"
emit " #check the boot protocol of the device"
emit " if [ \"\$BOOTPROTO\" == \"dhcp\" ]"
emit " then"
emit " RESULT=\`udhcpc -i \$REAL_DEV -q -n\`"
emit " if [ \$? != 0 ]"
emit " then"
emit " echo Unable to obtain an IP address, dropping to shell"
emit " /bin/msh"
emit " fi"
emit " IPADDR=\`echo \$RESULT | awk '{print \$14}'\`"
emit " fi"
emit " ifconfig \$REAL_DEV \$IPADDR netmask \$NETMASK"
emit " if [ -n \"\$GATEWAY\" ]"
emit " then"
emit " route add default gw \$GATEWAY"
emit " fi"
emit "done"
#grab remote host and xlate into numbers
rhost=`echo $location | sed 's/.*@//' | cut -d':' -f1`
need_dns=`echo $rhost|grep [a-zA-Z]`
@ -1230,8 +1300,6 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
echo "$KDUMP_CONFIG_FILE: Could not create temp directory in $location:/var/crash"
exit 1
fi
ssh -q $s_opts $rlocation rm -rf $tdir </dev/null
#TODO check for available size is greater than $memtotal
#setup ssh case, quick check to see if setup already
if [ ! -r $MNTIMAGE/dev/urandom ]; then
@ -1240,11 +1308,14 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
cp -a /root/.ssh $MNTIMAGE/root/
cp -a /etc/ssh $MNTIMAGE/etc
mknod $MNTIMAGE/dev/urandom c 1 9
emit "mknod /dev/urandom c 1 9"
fi
emit "dd if=/dev/mem of=/dev/urandom count=1 bs=512 skip=100"
emit "cond kcp --ssh /proc/vmcore $rlocation:/var/crash/$lhost-%DATE"
emit "cond reboot -f"
emit "ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no $rlocation mkdir /var/crash/$lhost-\$DATE"
emit "scp -q -o BatchMode=yes -o StrictHostKeyChecking=no /proc/vmcore $rlocation:/var/crash/$lhost-\$DATE/vmcore"
emit "if [ \$? == 0 ]"
emit "then"
emit " reboot -f"
emit "fi"
fi
;;
ifc)
@ -1274,13 +1345,12 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
if [ -z "$CORE_COLLECTOR" ]; then
CORE_COLLECTOR="cp"
fi
emit "DATE=\`date +%Y-%M-%d-%T\`"
emit "echo Saving to the local filesystem $location"
emit "fsck.$type $location"
emit "mount -t $type $location /mnt"
emit "if [ \$? == 0 ]"
emit "then"
emit " mkdir -p /proc/vmcore/var/crash/127.0.0.1-\$DATE"
emit " mkdir -p /mnt/var/crash/127.0.0.1-\$DATE"
emit " $CORE_COLLECTOR /proc/vmcore /mnt/var/crash/127.0.0.1-\$DATE/vmcore"
emit " if [ \$? == 0 ]"
emit " then"
@ -1320,14 +1390,26 @@ emit " mknod /dev/rootdev b 0x\$ROOT_MAJ 0x\$ROOT_MIN"
emit " ROOTDEV=/dev/rootdev"
emit "fi"
emit "echo Checking root filesystem."
emit "fsck \$ROOTDEV"
emit "echo Mounting root filesystem."
emit "mount \$ROOTDEV /sysroot"
emit "FSTYPE=\`fsck -N \$ROOTDEV | awk '/.*sbin.*/ {print \$1}' | sed -e's/\\(^.*\\.\\)\\(.*\\)/\\2/'\`"
emit "fsck -t \$FSTYPE \$ROOTDEV"
emit "echo mount -t \$FSTYPE \$ROOTDEV /sysroot"
emit "mount -t \$FSTYPE \$ROOTDEV /sysroot"
emit "if [ \$? != 0 ]"
emit "then"
emit " echo unable to mount rootfs. Dropping to shell"
emit " /bin/msh"
emit "fi"
emit "#move various filesystems and prime the rootfs to boot properly"
emit "umount /proc"
emit "mount -t proc proc /sysroot/proc"
emit "umount /sys"
emit "mount -t sysfs sysfs /sysroot/sys"
emit "mount -o bind /dev /sysroot/dev"
emit "touch /sysroot/fastboot"
emit "echo Switching to new root and running init."
emit "exec switch_root /sysroot /sbin/init"