Added
Link Here
|
1 |
#!/bin/sh |
2 |
|
3 |
exec_if_executable() |
4 |
{ |
5 |
local f |
6 |
f="$1" |
7 |
shift |
8 |
[ -x "$f" ] && "$f" "$@" |
9 |
} |
10 |
|
11 |
mdadm_found() |
12 |
{ |
13 |
[ -s /etc/mdadm.conf ] || return 1 |
14 |
local f |
15 |
for f in /sbin/mdadm /usr/sbin/mdadm /sbin/mdassemble /usr/sbin/mdassemble; do |
16 |
[ -x "$f" ] && return 0 |
17 |
done |
18 |
return 1 |
19 |
} |
20 |
|
21 |
raidtools_found() |
22 |
{ |
23 |
[ -s /etc/raidtab ] || return 1 |
24 |
local f |
25 |
for f in /sbin/raidstart /sbin/raid0run /sbin/raidadd; do |
26 |
[ -x "$f" ] && return 0 |
27 |
done |
28 |
return 1 |
29 |
} |
30 |
|
31 |
start_raid_using_mdadm() |
32 |
{ |
33 |
[ -s /etc/mdadm.conf ] || return 1 |
34 |
local f |
35 |
for f in /sbin/mdadm /usr/sbin/mdadm; do |
36 |
[ -x "$f" ] || continue |
37 |
echo -n "(using mdadm) " |
38 |
"$f" --assemble --scan |
39 |
return $? |
40 |
done |
41 |
for f in /sbin/mdassemble /usr/sbin/mdassemble; do |
42 |
[ -x "$f" ] || continue |
43 |
echo -n "(using mdassemble) " |
44 |
"$f" |
45 |
return $? |
46 |
done |
47 |
return 1 |
48 |
} |
49 |
|
50 |
start_raid_using_raidtools() |
51 |
{ |
52 |
[ -s /etc/raidtab ] || return 1 |
53 |
local rc=0 i dev stat res |
54 |
echo -n "(using raidtools) " |
55 |
for i in `grep -s "^raiddev" /etc/raidtab | awk '{print $2}'`; do |
56 |
dev="${i##*/}" |
57 |
stat=`grep -s "^$dev : active" /proc/mdstat` |
58 |
if [ -z "$stat" ]; then |
59 |
# Try raidstart first...if that fails then |
60 |
# fall back to raidadd, raidrun. If that |
61 |
# also fails, then we drop to a shell |
62 |
res=1 |
63 |
exec_if_executable /sbin/raidstart "$i" |
64 |
res=$? |
65 |
if [ $res -gt 0 ]; then |
66 |
exec_if_executable /sbin/raid0run "$i" |
67 |
res=$? |
68 |
fi |
69 |
if [ $res -gt 0 ]; then |
70 |
exec_if_executable /sbin/raidadd "$i" |
71 |
exec_if_executable /sbin/raidrun "$i" |
72 |
res=$? |
73 |
fi |
74 |
if [ $res -gt 0 ]; then |
75 |
rc=1 |
76 |
fi |
77 |
fi |
78 |
echo -n "$dev " |
79 |
done |
80 |
return $rc |
81 |
} |
82 |
|
83 |
[ -f /proc/mdstat ] && ! grep -iwqs noraidtab /proc/cmdline || exit 0 |
84 |
|
85 |
rc=0 |
86 |
if mdadm_found; then |
87 |
echo -n "Starting up RAID devices: " |
88 |
start_raid_using_mdadm |
89 |
rc=$? |
90 |
echo |
91 |
elif raidtools_found; then |
92 |
echo -n "Starting up RAID devices: " |
93 |
start_raid_using_raidtools |
94 |
rc=$? |
95 |
echo |
96 |
fi |
97 |
exit $rc |