Merge branch 'zrlang'

This commit is contained in:
qinbo
2010-09-21 14:07:01 +08:00
3 changed files with 207 additions and 4 deletions

204
operation/mkTmpfstab.sh Executable file
View File

@@ -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
<oldfstab> -- specify the path of the initial fstab.
<tmpfstab> -- 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 <zrlang@linx-info.com>"
}
###########################################################################
# 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

View File

@@ -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,7 @@ testBeforeMkraid(){
# used"
for i in $DEVICELIST
do
mdadm -E $i >>${LOGDIR}${LOGFILE} 2>>${LOGDIR}${LOGFILE}
if [ $? == "0" ]; then
if mdadm -Ds -v | grep -w $i ; then
ERRNO="6"
return 1
fi

View File

@@ -29,5 +29,5 @@ if [ ! -d $CONDIR ]; then
exit 1
fi
fi
mdadm -Es -v > $CONDIR$CONFILE
mdadm -Ds -v > $CONDIR$CONFILE