#!/bin/sh
main () {
clear
echo ‘ ------------------------------------------------------ ‘
echo ‘ 1.Create a software raid array ‘
echo ‘ 2.View raid array sync status ‘
echo ‘ 3.View raid array detail ‘
echo ‘ 4.Create mdadm.conf file ‘
echo ‘ 5.Add hotspare device on raid array ‘
echo ‘ 6.Replace a fault device on raid array ‘
echo ‘ 7.Delete a software raid array ‘
echo ‘ 8.Renaming a raid array ‘
echo ‘ 9.Resync raid array ‘
echo ‘ q,exit ‘
echo ‘ ------------------------------------------------------ ‘
while true
do
echo -n " Please choice [1-q]:"
read choice
case $choice in
1)
create_raid
sleep 10
clear
main
;;
2)
view_sync
clear
main
;;
3)
view_detail
sleep 10
clear
main
;;
4)
create_configure_file
sleep 3
clear
main
;;
5)
add_hot
sleep 10
clear
main
;;
6)
view_detail
sleep 5
rep_dev
clear
main
;;
7)
del_rd
clear
main
;;
8)
ren_rd
view_detail
sleep 5
clear
main
;;
9)
res_rd
clear
view_sync
clear
main
;;
q)
exit
;;
esac
done
}
#create raid
create_raid (){
if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
echo
echo "Please input the name:[like:md0,md1....]"
read name
echo
echo "which level do you want to create it?[0,1,5,6]"
echo "The level 0 and 1 at least 2 device,The level 5 at least 3 device,level 6 at least 4."
read level
echo
echo "How many device for use?"
read num
echo "The device name like:/dev/sda,/dev/sda1,/dev/sd[abcd],/dev/sd[abcd]1"
echo "Please input the device name:"
read input
mdadm -C /dev/$name -l$level -n$num $input
fi
}
#view sync status
view_sync () {
if [ -e /proc/mdstat ]&&[ -r /proc/mdstat ];then
watch -n .2 ‘cat /proc/mdstat‘
fi
}
#view detail of md information
view_detail () {
if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
echo "which md device you want to view detail:"
read input
if [ $input=`grep $input /proc/mdstat |awk ‘{print $1}‘` ];then
mdadm --detail /dev/$input
else
sleep 5
fi
fi
}
#create mdadm configure file
create_configure_file () {
if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
echo "The mdadm.conf file default location is /etc."
mdadm --examine --scan >/etc/mdadm.conf
echo "The mdadm.conf file content by follow:"
cat /etc/mdadm.conf
fi
}
#add hotspare device
add_hot () {
if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
echo "which md do you for add a hotspare device?"
read name
echo "which device you want set a hotspare?"
read device
mdadm /dev/$name -a $device
mdadm --detail /dev/$name
fi
}
#remove a fault device
rep_dev () {
if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
echo "Which device you want to remove?"
read device1
echo "Which device you want to add?"
read device2
mdadm -r $device1 -a $device2
fi
}
#delete a raid
del_rd () {
echo "First,stop all I/O access on md devices."
if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
echo "Which md do you want to delete?"
read md
mdadm -S /dev/$md
echo "Please input the device name:"
read name
mdadm --misc --zero-superblock $name
fi
}
#renaming a raid array
ren_rd () {
echo "First,you must stop the raid array!"
if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
echo "Which md do you want stop?"
read md
mdadm -S /dev/$md
echo "What‘s the new md name?"
read name
echo "What‘s the device name on the old md?"
read device
mdadm --assemble /dev/$name --super-minor=0 --update=super-minor $device
fi
}
#resync a raid array
res_rd () {
echo "Which raid array need resync?"
read input
if [ -e /sys/block/$input/md/sync_action ]&&[ -f /sys/block/$input/md/sync_action ];then
echo check >/sys/block/$input/md/sync_action
fi
}
#Calling main function
main
#EOF
Crazy_Linux !
Centos 6下软raid操作脚本,布布扣,bubuko.com