projects/aports·blob master · refs

48 lines · 971 B

1#!/sbin/openrc-run
2
3# script to start raid devices described in /etc/mdadm.conf.
4depend() {
5 before checkfs fsck swap
6 after modules
7}
8
9array_devices() {
10 awk '/^ARRAY/ {print $2}' /etc/mdadm.conf
11}
12
13start() {
14 [ -f /etc/mdadm.conf ] || return 0
15 # start all devices that are not already started
16 [ -f /proc/mdstat ] || modprobe md > /dev/null 2>&1
17 local tostart=
18 for i in $(array_devices); do
19 [ -b "$i" ] && continue
20 tostart="$tostart $i"
21 done
22 [ -z "$tostart" ] && return 0
23
24 ebegin "Starting RAID devices"
25 mdadm --assemble --scan --quiet $tostart
26 eend $?
27}
28
29is_mounted_as() {
30 local mnt
31 for mnt in $(lsblk -o MOUNTPOINT $1); do
32 [ "$mnt" = "$2" ] && return 0
33 done
34 return 1
35}
36
37stop() {
38 # stop all raid devices except anything mounted as /
39 [ -f /etc/mdadm.conf ] || return 0
40 ebegin "Stopping RAID devices"
41 local tostop=
42 for i in $(array_devices); do
43 is_mounted_as $i / && continue
44 tostop="$tostop $i"
45 done
46 mdadm --stop --quiet $tostop
47 eend $?
48}