From e81f9da38494955169b4273b5f05b3fa691fc867 Mon Sep 17 00:00:00 2001 From: zrlang Date: Fri, 10 Sep 2010 09:10:21 +0800 Subject: [PATCH 1/4] Second modify for old stopped raid --- operation/mkraid.sh | 6 +++--- operation/mkraidconf.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/operation/mkraid.sh b/operation/mkraid.sh index 5ed5399..3d763fc 100755 --- a/operation/mkraid.sh +++ b/operation/mkraid.sh @@ -128,7 +128,7 @@ setArgument(){ testBeforeMkraid(){ local i #test the "(3) mdX has exist" error - mdadm -Q $RAIDNAME >>${LOGDIR}${LOGFILE} 2>>${LOGDIR}${LOGFILE} + mdadm -D $RAIDNAME >>${LOGDIR}${LOGFILE} 2>>${LOGDIR}${LOGFILE} if [ $? == "0" ]; then ERRNO="3" return 1 @@ -164,8 +164,8 @@ testBeforeMkraid(){ # used" for i in $DEVICELIST do - mdadm -E $i >>${LOGDIR}${LOGFILE} 2>>${LOGDIR}${LOGFILE} - if [ $? == "0" ]; then + if [ mdadm -Ds -v | grep $i ];then # >>${LOGDIR}${LOGFILE} 2>>${LOGDIR}${LOGFILE} +# if [ $? == "0" ]; then ERRNO="6" return 1 fi diff --git a/operation/mkraidconf.sh b/operation/mkraidconf.sh index b349841..b20ec66 100755 --- a/operation/mkraidconf.sh +++ b/operation/mkraidconf.sh @@ -29,5 +29,5 @@ if [ ! -d $CONDIR ]; then exit 1 fi fi -mdadm -Es -v > $CONDIR$CONFILE +mdadm -Ds -v > $CONDIR$CONFILE From 3ff980a5919b92abd197fa865d7435cdce484f95 Mon Sep 17 00:00:00 2001 From: zrlang Date: Fri, 10 Sep 2010 10:19:10 +0800 Subject: [PATCH 2/4] third modify for mkraid --- operation/mkraid.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/operation/mkraid.sh b/operation/mkraid.sh index 3d763fc..7a421d0 100755 --- a/operation/mkraid.sh +++ b/operation/mkraid.sh @@ -164,8 +164,7 @@ testBeforeMkraid(){ # used" for i in $DEVICELIST do - if [ mdadm -Ds -v | grep $i ];then # >>${LOGDIR}${LOGFILE} 2>>${LOGDIR}${LOGFILE} -# if [ $? == "0" ]; then + if [ mdadm -Ds -v | grep -w $i ];then ERRNO="6" return 1 fi From 17aed729af9aaeac3e25130a02d3a4c05dcf50b1 Mon Sep 17 00:00:00 2001 From: zrlang Date: Fri, 10 Sep 2010 11:19:34 +0800 Subject: [PATCH 3/4] third(2) modify --- operation/mkraid.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operation/mkraid.sh b/operation/mkraid.sh index 7a421d0..afe34d2 100755 --- a/operation/mkraid.sh +++ b/operation/mkraid.sh @@ -164,7 +164,7 @@ testBeforeMkraid(){ # used" for i in $DEVICELIST do - if [ mdadm -Ds -v | grep -w $i ];then + if mdadm -Ds -v | grep -w $i ; then ERRNO="6" return 1 fi From 966b50e432aee9c797c51a66d27d88ab99c3645f Mon Sep 17 00:00:00 2001 From: zorro Date: Tue, 21 Sep 2010 10:50:29 +0800 Subject: [PATCH 4/4] make temp fstab for make initrd --- operation/mkTmpfstab.sh | 204 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100755 operation/mkTmpfstab.sh diff --git a/operation/mkTmpfstab.sh b/operation/mkTmpfstab.sh new file mode 100755 index 0000000..3aa27bc --- /dev/null +++ b/operation/mkTmpfstab.sh @@ -0,0 +1,204 @@ +#! /bin/bash + +############################################################################ +# DESCRIPTION: This shell is made for the bug of the mkinitrd-5.1.19.6 from +# Redhat. The bug is that we can get the true raid device name +# by UUID in fstab. So this file try to modify this bug. +# +# SCRIPT NAME: mkTmpfstab.sh +# +# argument: <-f|--from> specify the path of the old fstab +# <-t|--to> specify the path of the temp fstab +# +# return value: 1 false to make the file +# 0 make allright +# +# AUTHOR: ZR_Lang +# +# EMALL: zrlang@linx-info.com +# +# DATE: 2010-09-16 +# +# HISTORY: +# REVISOR DATE MODIFICATION +# ZR_Lang 2010-09-16 create +########################################################################### +PATHFROM='' +PATHTO='' + +LOGDIR="/var/log/" +LOGFILE="mkTmpfstab.log" + +########################################################################### +# Function Name: setArgument() +# Input: $@ +# Return: nothing +# Description: set the corresponding argument +########################################################################### +setArgument(){ + ARGV_MKFSTAB=($(getopt -l from:,to: -o f:,t: -- $@ 2>>$LOGDIR$LOGFILE)) + for((i=0; i<${#ARGV_MKFSTAB[@]}; i++)) + do + case ${ARGV_MKFSTAB[$i]} in + --from) + ((i++)) + PATHFROM=${ARGV_MKFSTAB[$i]} + ;; + --to) + ((i++)) + PATHTO=${ARGV_MKFSTAB[$i]} + ;; + -f) + ((i++)) + PATHFROM=${ARGV_MKFSTAB[$i]} + ;; + -t) + ((i++)) + PATHTO=${ARGV_MKFSTAB[$i]} + ;; + --) + break + ;; + *) + echo "error argument, please use help message" >>$LOGDIR$LOGFILE + exit 1 + ;; + esac + done + + PATHFROM=`echo $PATHFROM| sed -e s/\'/''/g` + PATHTO=`echo $PATHTO| sed -e s/\'/''/g` +} + +########################################################################### +# Function Name: cpTmpfstab() +# Input: $PATHFROM $PATHTO +# Return: nothing +# Description: copy the old fstab to a temp place +########################################################################### +cpTmpfstab(){ + local i + local TMPPATH=`echo "$2"|sed -e s/[/]/' '/g` + for i in $TMPPATH + do + continue + done + local PATHTOFILE=$i + local PATHTODIR=`echo "$2"|sed -e s/"$PATHTOFILE"/''/g` + + mkdir -p $PATHTODIR 2>>$LOGDIR$LOGFILE + if [ $? != "0" ];then + echo "can not makedir named $PATHTODIR" >>$LOGDIR$LOGFILE + exit 1 + fi + cp $1 $2 2>>$LOGDIR$LOGFILE + if [ $? != "0" ]; then + echo "can not copy $1 to $2" >>$LOGDIR$LOGFILE + exit 1 + fi +} + +########################################################################### +# Function Name: mdfyTmpFstab() +# Input: $PATHTO +# Return: nothing +# Description: modify the temp fstab, change UUID to the right device name +########################################################################### +mdfyTmpFstab(){ + local i + local j + local LASTNAME='' + local UUIDFROMFSTAB=$(awk '/^[ \t]*[^#]/ { if ($1 ~ "^[UUID]") { print $1}}' $1) + for i in $UUIDFROMFSTAB + do + blkid -t$i >/tmp/.blkid.tmp + local NAMEFROMUUID=`cut -f 1 -d : /tmp/.blkid.tmp` + if [ ! "${NAMEFROMUUID}" ];then + echo "error UUID, can not find devices by blkid" >>$LOGDIR$LOGFILE + exit 1 + fi + + if [ `echo $NAMEFROMUUID| wc -w` -lt 2 ];then + LASTNAME=$NAMEFROMUUID + else + for j in $NAMEFROMUUID + do + if [ `echo $j|grep 'md'` ];then + if [ ! $LASTNAME ]; then + LASTNAME=$j + else + echo "too many raid devices be found" >>$LOGDIR$LOGFILE + exit 1 + fi + else + if [ `mdadm -Ds -v|grep -w $j` ];then + continue + else + echo "too many partitions be found" >>$LOGDIR$LOGFILE + exit 1 + fi + fi + done + fi + sed -i s@$i@$LASTNAME@g $1 + LASTNAME='' + done + rm /tmp/.blkid.tmp +} + +########################################################################### +# Function Name: usage() +# Input: nothing +# Return: nothing +# Description: print the helped message +########################################################################### +usage(){ + echo "Usage: mkraid [-h|--help] <-f|--from oldfstab> <-t|--to tmpfstab>" + echo "This shell is just used to modify a false of mkinitrd, when used UUID to specify a raid device in fstab the mkinitrd always analysis false, not only one devices would be found according to the UUID. So I write this shell for makeinitrd. The shell will take the old fstab(usually is /etc/fstab) to a temp place, then change the UUID to right device name in the temp fstab. The makeinitrd shell should use the temp fstab file to make the initrd and stay the old fstab, after make initrd remove the temp fstab." + echo"" + echo "ARGUMENT: + [-h|--help] -- print the helped message + -- specify the path of the initial fstab. + -- specify the temp path of a new fstab, the makeinitrd will use the temp fstab to make initrd." + echo "" + echo "RETURN VALUE: + 1 make temp fstab error + 0 make allright +the log message will be print in $LOGDIR$LOGFILE" + echo "" + echo "EXAMPLE: +If you want to according /etc/fstab to make a temp fstab file in /tmp named .fstab.tmp, you can write for this:" + echo "" + echo " mkTmpfstab.sh -f /etc/fstab -t /tmp/.fstab.tmp " + echo "The /tmp/.fstab.tmp will be the argument of the option named --fstab of mkinitrd. If you use this shell please remember this." + echo "" + echo "" + echo "Report bugs to " +} + + +########################################################################### +# main from here # +########################################################################### +if [ $1 == "--help" -o $1 == "-h" ];then + usage + exit 0 +elif [ $# -lt 4 ];then + echo "need more arguments, please look at the helped message" + exit 1 +fi + +#initial the log file +if [ -d $LOGDIR ];then + mkdir -p $LOGDIR + touch $LOGDIR$LOGFILE +fi +NOWDATE=`date` +echo $NOWDATE >>$LOGDIR$LOGFILE + +setArgument $@ +cpTmpfstab $PATHFROM $PATHTO +mdfyTmpFstab $PATHTO +echo "make temp fstab all right" >>$LOGDIR$LOGFILE + +# End of file