martin f. krafft: updated newdisk script ver 1.40

Martin F. Krafft madduck at alioth.debian.org
Wed Oct 15 09:47:18 UTC 2008


Module: mdadm
Branch: build
Commit: 1af2b398f11c99029595b288342e10a83fd756a7
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=1af2b398f11c99029595b288342e10a83fd756a7

Author: martin f. krafft <madduck at madduck.net>
Date:   Tue Jul 15 18:19:44 2008 +0200

updated newdisk script ver 1.40

---

 debian/changelog |    2 +
 debian/newdisk   |   79 +++++++++++++++++++++++++++++------------------------
 2 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 558be49..e7aba7c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
 mdadm (2.6.7-4) unstable; urgency=low
 
   * Add David Pashley's Rebuilding RAID blog post.
+  * Add new (bugfix) version 1.40 of the newdisk script
+    (/usr/share/doc/mdadm/examples/newdisk.gz) (closes: #490955).
 
  -- martin f. krafft <madduck at debian.org>  Sat, 12 Jul 2008 23:37:20 +0200
 
diff --git a/debian/newdisk b/debian/newdisk
index 503d4a0..7c18339 100755
--- a/debian/newdisk
+++ b/debian/newdisk
@@ -1,10 +1,10 @@
 #!/bin/sh
 
-MY_VERSION="1.33-WIP"
+MY_VERSION="1.40"
 # ----------------------------------------------------------------------------------------------------------------------
 # Linux MD (Soft)RAID Add Script - Add a (new) harddisk to another multi MD-array harddisk
-# Last update: May 4, 2007
-# (C) Copyright 2005-2007 by Arno van Amersfoort
+# Last update: July 15, 2008
+# (C) Copyright 2005-2008 by Arno van Amersfoort
 # Homepage              : http://rocky.eld.leidenuniv.nl/
 # Email                 : a r n o v a AT r o c k y DOT e l d DOT l e i d e n u n i v DOT n l
 #                         (note: you must remove all spaces and substitute the @ and the . at the proper locations!)
@@ -26,7 +26,7 @@ MY_VERSION="1.33-WIP"
 show_help()
 {
   echo "Bad or missing parameter(s)"
-  echo "Usage: `basename $0` [ source_disk ] [ target_disk ] [ options ]"
+  echo "Usage: $(basename $0) [ source_disk ] [ target_disk ] [ options ]"
   echo "Options:"
   echo "--force       = Even proceed if target device does not appear empty"
   echo "--noptupdate  = Do NOT update the partition table on the target device (EXPERT!)"
@@ -67,8 +67,8 @@ TARGET=""
 
 # Check arguments
 for arg in $*; do
-  ARGNAME=`echo "$arg" |cut -d= -f1`
-  ARGVAL=`echo "$arg" |cut -d= -f2`
+  ARGNAME="$(echo "$arg" |cut -d= -f1)"
+  ARGVAL="$(echo "$arg" |cut -d= -f2)"
 
   if ! echo "$ARGNAME" |grep -q "^-"; then
     if [ -z "$SOURCE" ]; then
@@ -78,7 +78,7 @@ for arg in $*; do
         TARGET="$ARGVAL"
       else
         show_help;
-        exit 2
+        exit 3
       fi
     fi
   else
@@ -90,7 +90,7 @@ for arg in $*; do
               exit 0;;
       *) echo "ERROR: Bad argument: $ARGNAME";
          show_help;
-         exit 4;;
+         exit 3;;
     esac
   fi
 done
@@ -98,23 +98,23 @@ done
 if [ -z "$SOURCE" ] || [ -z "$TARGET" ]; then
   echo "ERROR: Bad or missing argument(s)"
   show_help;
-  exit 2
+  exit 4
 fi
 
 if ! echo "$SOURCE" |grep -q '^/dev/'; then
   printf "\033[40m\033[1;31mERROR: Source device $SOURCE does not start with /dev/! Quitting...\n\033[0m"
-  exit 6
+  exit 5
 fi
 
 if ! echo "$TARGET" |grep -q '^/dev/'; then
   printf "\033[40m\033[1;31mERROR: Target device $TARGET does not start with /dev/! Quitting...\n\033[0m"
-  exit 7
+  exit 6
 fi
 
 if echo "$SOURCE" |grep -q 'md'; then
   printf "\033[40m\033[1;31mERROR: The source device specified is an md-device! Quitting...\n\033[0m"
   echo "A physical drive (part of the md-array('s)) is required as source device (ie. /dev/hda)!"
-  exit 8
+  exit 7
 fi
 
 # We also want variables without /dev/ :
@@ -123,22 +123,22 @@ TARGET_NODEV="$(echo "$TARGET" |sed s,'^/dev/',,)"
 
 if ! grep -q -e " $TARGET_NODEV " -e " $TARGET_NODEV$" /proc/partitions; then
   printf "\033[40m\033[1;31mERROR: Target device $TARGET is NOT a valid target drive! Quitting...\n\033[0m"
-  exit 9
+  exit 8
 fi
 
 if ! grep -q -e " $SOURCE_NODEV " -e " $SOURCE_NODEV$" /proc/partitions; then
   printf "\033[40m\033[1;31mERROR: Source device $SOURCE is NOT a valid source drive! Quitting...\n\033[0m"
-  exit 10
+  exit 9
 fi
 
 if ! grep -q -e " $SOURCE_NODEV[p,1..9]" /proc/partitions; then
   printf "\033[40m\033[1;31mERROR: Source device $SOURCE does not contain any partitions!? Quitting...\n\033[0m"
-  exit 11
+  exit 10
 fi
 
 if grep -q -e " $TARGET_NODEV[p,1..9]" /proc/partitions && [ "$FORCE" != "1" ]; then
   printf "\033[40m\033[1;31mERROR: Target device $TARGET is NOT empty! Use --force to override. Quitting...\n\033[0m"
-  exit 13
+  exit 11
 fi
 
 if grep -q -e " $TARGET_NODEV" /proc/mdstat; then
@@ -173,38 +173,41 @@ else
   sfdisk -d "$SOURCE" |sfdisk --force "$TARGET"
 fi
 
+mdadm --detail --scan --verbose >/tmp/mdadm-detail-scan.txt
+retval=$?
+if [ "$retval" != "0" ]; then
+  printf "\033[40m\033[1;31mERROR: MDADM returned an error($retval) while determining detail information!\n\033[0m"
+  exit 12
+fi
+
 # Copy/build all md devices that exist on the source drive:
 BOOT=0
-NOTHING=1
+NO_ADD=1
 while read STRING; do
-  if echo "$STRING" |grep -q -e " $SOURCE_NODEV"; then
-    NOTHING=0
-    MD_DEV=$(echo "$STRING" |awk '{ print $1 }')
-#    PARTITION=$(echo "$STRING" |awk '{ print $5 }' |sed s,'\[.\]',, |sed s,'^...',,)
-    PARTITION_NR="$(mdadm --detail "/dev/$MD_DEV" |grep "active sync" |awk '{ print $NF }' |grep "^$SOURCE" |head -n1 |sed s,"^$SOURCE",,)"
-    retval=$?
-
-    if [ "$retval" != "0" ]; then
-      printf "\033[40m\033[1;31mERROR: MDADM returned an error($retval) while determining detail information for $SOURCE from /dev/$MD_DEV!\n\033[0m"
-      exit 14
-    fi
+  if echo "$STRING" |grep -q "^ARRAY "; then
+    MD_DEV=$(echo "$STRING" |awk '{ print $2 }')
+  fi
+  
+  if echo "$STRING" |grep -q "devices=.*$SOURCE"; then
+    NO_ADD=0
+    PARTITION_NR="$(echo "$STRING" |sed -e s:".*devices=.*$SOURCE":"": -e s:",.*":"":)"
 
     if [ -z "$PARTITION_NR" ]; then
-      printf "\033[40m\033[1;31mERROR: Unable to retrieve detail information for $SOURCE from /dev/$MD_DEV!\n\033[0m"
-      exit 15
+      printf "\033[40m\033[1;31mERROR: Unable to retrieve detail information for $SOURCE from $MD_DEV!\n\033[0m"
+      exit 13
     fi
 
-    if grep -q -e "^/dev/$MD_DEV.*/boot" -e "^/dev/$MD_DEV.*/.*1$" /etc/fstab; then
+    if grep -q -e "^$MD_DEV.*/boot" -e "^$MD_DEV.*/.*1$" /etc/fstab; then
       BOOT=1
     fi
 
     echo ""
-    echo "--> Adding $TARGET$PARTITION_NR to RAID array /dev/$MD_DEV:"
+    echo "--> Adding $TARGET$PARTITION_NR to RAID array $MD_DEV:"
     printf "\033[40m\033[1;31m"
-    mdadm --add "/dev/$MD_DEV" "$TARGET""$PARTITION_NR"
+    mdadm --add "$MD_DEV" "$TARGET""$PARTITION_NR"
     printf "\033[0m"
   fi
-done < /proc/mdstat
+done < /tmp/mdadm-detail-scan.txt
 
 echo ""
 
@@ -226,11 +229,15 @@ echo "--> Showing current /proc/mdstat (you may need to update your mdadm.conf (
 cat /proc/mdstat
 echo ""
 
-if [ "$NOTHING" = "1" ]; then
+if [ "$NO_ADD" = "1" ]; then
   printf "\033[40m\033[1;31mWARNING: No mdadm --add actions were performed, please investigate!\n\033[0m"
 fi
 
 if [ "$BOOT" = "1" ]; then
-  printf "\033[40m\033[1;31mNOTE: Boot and/or root partition detected. Although the MBR was copied,\n      you *MAY* need to reinstall your boot loader (ie. GRUB) on this device!\n\033[0m"
+  printf "\033[40m\033[1;31mNOTE: Boot and/or root partition detected.\n      You *MAY* need to reinstall your boot loader (ie. GRUB) on this device!\n\033[0m"
 fi
 
+# TODO?:
+# sanity check nopt (check if target device has a partition table)?
+# detect if device has superblock (mdadm --examine /dev/sda1; echo $?)?
+# continue ask (show what will be done):?




More information about the pkg-mdadm-commits mailing list