rpms/kexec-tools/devel mkdumprd,1.7,1.8

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Fri Sep 22 19:09:04 UTC 2006


Author: nhorman

Update of /cvs/dist/rpms/kexec-tools/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv4213

Modified Files:
	mkdumprd 
Log Message:
further updates to mkdumprd for scp dumping with busybox


Index: mkdumprd
===================================================================
RCS file: /cvs/dist/rpms/kexec-tools/devel/mkdumprd,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- mkdumprd	18 Sep 2006 17:59:46 -0000	1.7
+++ mkdumprd	22 Sep 2006 19:09:02 -0000	1.8
@@ -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 at redhat.com>
 #       Guillaume Cottenceau <gc at mandrakesoft.com>
 #	Peter Jones <pjones at redhat.com>
+#       Neil Horman <nhorman at redhat.com>
 
 umask 0022
 
@@ -386,7 +387,7 @@
 
 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 @@
     [ -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 @@
         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 @@
             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/sys
 mkdir -p $MNTIMAGE/sysroot
 mkdir -p $MNTIMAGE/modules
+mkdir -p $MNTIMAGE/usr/share/udhcpc
 ln -s bin $MNTIMAGE/sbin
 
 
@@ -941,6 +963,13 @@
 
 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 @@
 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/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_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 @@
     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 @@
     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 @@
                     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 @@
                             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 @@
                             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 [ -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 "   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"
 




More information about the fedora-cvs-commits mailing list