[ UP ] cgi
[archserver.git] / cgi / raid / list_disks.sh
blob54a3d185460a5fd53dcc6188ce1337c014d84ab9
1 #!/bin/sh
3 echo -e '
4 <form action = "volumes_create_raid.cgi" method = "post">
6 <h3>1. 选择阵列类型: </h3>
7 <div class="messageblock messageblock-info">
8 <div class="messageblock-internal">
9 <p> Select a Raid type in the list below.</p>
10 </div></div> 选择阵列类型:
11 <select name="raid_method">
12 <option value="no">无阵列</option>
13 <option value="raid0">Raid-0</option>
14 <option value="raid1">Raid-1</option>
15 <option value="raid5">Raid-5</option>
16 <option value="raid6">Raid-6</option>
17 <option value="raid10">Raid-10</option>
18 </select>
19 <br><br><br>
22 sudo fdisk -l | grep 'Disk /dev' | sed 's:.*\(/dev.*GB\).*:\1:' >/tmp/disks.tmp
25 echo -e '
26 <h3>2. 选择可用磁盘:</h3>
27 <div class="messageblock messageblock-info">
28 <div class="messageblock-internal"><p>
29 创建Raid-0, Raid-1 至少要两块硬盘. Raid-5 需要3块硬盘. Raid-6, Raid-10至少需要4块硬盘.<br>
30 选中的硬盘将被格式化,数据将被破坏.
31 </p></div></div>
32 <br><br>
34 <table cellspacing="2" cellpadding="8" border="0" width="95%">
35 <tr align="center"><td bgcolor="#ebebeb"><strong>硬盘</strong></td><td bgcolor="#ebebeb"><strong>容量</strong></td><td bgcolor="#ebebeb"><strong>型号</strong></td><td bgcolor="#ebebeb"><strong>状态</strong></td></tr>
38 count=1
39 while read line
41 dev=$(echo $line | cut -f1 -d:)
42 size=$(echo $line | cut -f2 -d:)
43 model=$(sudo hdparm -I $dev| grep 'Model Number' | cut -f2 -d: | tr -s ' ')
44 let _n=$count%2+1
45 if df -h | grep -q $dev; then
46 echo "<tr bgcolor="#c6d5a8" align="center"><td><input type=\"checkbox\" name=\"devs_$count\" value=\"$dev\">
47 $dev </td><td>$size</td><td>$model</td><td><font color=red>"正在使用"</font></td></tr>"
48 elif cat /proc/swaps | grep -q $dev; then
49 echo "<tr bgcolor="#c6d5a8" align="center"><td><input type=\"checkbox\" name=\"devs_$count\" value=\"$dev\">
50 $dev </td><td>$size</td><td>$model</td><td><font color=red>"使用\(swap\)"</font></td></tr>"
51 else
52 echo "<tr bgcolor="#c6d5a8" align="center"><td><input type=\"checkbox\" name=\"devs_$count\" value=\"$dev\">
53 $dev </td><td>$size</td><td>$model</td><td>"未使用"</td></tr>"
56 let count=$count+1
57 done < /tmp/disks.tmp
58 echo "</table><br><br><hr>"
62 echo -e '
63 <br><h3>3. 选择热备盘</h3>
65 <div class="messageblock messageblock-info">
66 <div class="messageblock-internal">
67 <p> 热备盘是未被使用的空闲硬盘。在Raid阵列中若有磁盘失效,系统会自动用热备盘替换,以确保数据安全性.<br>
68 提示:热备盘必须是空闲硬盘,上面创建Raid的硬盘不能被使用.</p>
69 </div></div>
70 <select name="hot_spare" >
72 devs="<option value=\"no\">无热备盘</option>"
73 while read line
75 dev=$(echo $line | cut -f1 -d:)
76 devs="$devs <option value=$dev>$dev</option>"
77 done < /tmp/disks.tmp
78 echo $devs
79 echo "</select>"
81 echo -e '
82 <br><br><br><hr>
83 <input type="submit" value="创建阵列")
84 </form>
86 rm -f /tmp/disks.tmp