6 all_disks
="$F_devs_1 $F_devs_2 $F_devs_3 $F_devs_4 $F_devs_5 $F_devs_6 $F_devs_7 $F_devs_8 $F_devs_9 $F_devs_10 $F_devs_11 $F_devs_12 $F_devs_13 $F_devs_14 $F_devs_15 "
8 echo -e "all: $all_disks<br>"
9 echo -e "hotspare: $F_hot_spare<br>"
10 echo -e "Raid Method: $F_raid_method<br>"
12 if [ "$F_raid_method" = "no" ]; then
13 h_error
"Error: No Raid Type Selected.";
14 elif [ "$all_disks" = "" ]; then
15 h_error
"Error: No Disks Selected.";
18 disk_nu
=$
(echo $all_disks |
wc -w)
19 echo -e "Disks: $all_disks<br>"
20 echo "disk number: $disk_nu<br>"
23 ####################################################
24 # Some check with the parameters ! #
25 ####################################################
28 if [ "$m" = "raid0" -a $disk_nu -lt 2 ] ||
[ "$m" = "raid1" -a $disk_nu -lt 2 ]; then
29 h_error
"Error: $m need 2 disk at lease";
30 elif [ "$m" = "raid5" -a $disk_nu -lt 3 ]; then
31 h_error
"Error: $m need 3 disk at least";
32 elif [ "$m" = "raid6" -a $disk_nu -lt 4 ] ||
[ "$m" = "raid10" -a $disk_nu -lt 4 ]; then
33 h_error
"Error: $m need 4 disk at least";
37 # check whether spare disk is used.
38 for h
in `echo -e $F_hot_spare`
40 if echo -e $all_disks |
grep -q $h; then
41 h_error
-e $F_hot_spare" exist in disks!";
45 #check whether DISK is mounted now.
46 for d
in `echo -e $all_disks`
48 if df |
grep -q $d; then
49 mdisk
=`df | grep $d | awk '{print $NF}'`
50 h_error
"$d is mounted on \"$mdisk\""
51 elif grep -q $d /proc
/swaps
; then
52 h_error
"$d is mounted on Swap"
58 ####################################################
60 ####################################################
62 echo -e "<br>正在创建阵列...<br><font color=red>
63 sudo /sbin/mdadm -C /dev/md0 -R -l`echo $m|sed 's/raid//'`
64 `echo -e $all_disks|sed 's/ /2 /g'|sed 's/$/2/g'` `[ "$F_hot_spare" = "no
" ] || echo "-x $F_hot_spare"` >/tmp/xxxx.err 2>&1 ||
65 h_error $(cat /tmp/xxxx.err; rm /tmp/xxxx.err)
69 eval echo "正在格式化阵列为 XFS 文件系统...<br>"
70 eval eval sudo mkfs.xfs -f /dev/md0 $E
71 eval echo "正在把挂栽阵列到系统上...<br>"
72 eval sudo mkdir /tmp/tempdir $E
73 eval sudo mount /dev/md0 /tmp/tempdir $E
74 eval sudo cp -rdf --preserve /home/* /tmp/tempdir $E
75 eval sudo umount /dev/md0 $E
76 eval sudo mount /dev/md0 /home $E
77 #FIXME: found a simple way to operate with /etc/fstab
78 if ! grep -q "/dev/md0" /etc/fstab; then
79 sudo cat /etc/fstab > /tmp/fstab
80 sudo echo "/dev/md0 /home xfs defaults 0 0" 2>&1 >> /tmp/fstab
81 sudo mv /tmp/fstab /etc/fstab
85 # Formmat each disk to two partitions:
86 # 1. linux-swap,256MB 2. xfs, all left size.
87 #for d in `echo -e $all_disks`
89 # echo "正在为硬盘[ $d ]分区 ...<br>"
90 # disksize=`sudo parted $d p | grep '^Disk /dev/.*' | cut -f 3 -d" "`
91 # sudo parted -s $d mklabel msdos 2>&1 || exit
92 # sudo parted -s $d mkpart primary linux-swap 0 512 2>&1 || exit
93 # sudo parted -s $d mkpart primary xfs 512 $disksize 2>&1 || exit
95 # sleep 2 # wait for parted completed.
96 # sudo /sbin/mkswap -L swap $d1 2>&1 >/dev/null || exit
97 # sudo swapon $d1 2>&1
98 # #FIXME: found a simple way to operate with /etc/fstab
99 # if ! grep -q "$d1" /etc/fstab; then
100 # sudo cat /etc/fstab > /tmp/fstab
101 # sudo echo "$d1 swap swap defaults 0 0" 2>&1 >> /tmp/fstab
102 # sudo mv /tmp/fstab /etc/fstab
106 echo "Raid $F_raid_method 创建成功!"