summaryrefslogtreecommitdiff
blob: 0ada6a8bf0a287d297b66470bc1543d1b975e176 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# /lib/rcscripts/addons/raid-start.sh:  Setup raid volumes at boot
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/mdadm/files/raid-start.sh,v 1.5 2006/11/10 00:27:07 vapier Exp $

[[ -f /proc/mdstat ]] || exit 0

# We could make this dynamic, but eh
#[[ -z ${MAJOR} ]] && export MAJOR=$(awk '$2 == "md" { print $1 }' /proc/devices)
MAJOR=9

# Try to make sure the devices exist before we use them
create_devs() {
	local node dir minor
	for node in $@ ; do
		[[ ${node} != /dev/* ]] && node=/dev/${node}
		[[ -e ${node} ]] && continue

		dir=${node%/*}
		[[ ! -d ${dir} ]] && mkdir -p "${dir}"

		minor=${node##*/}
		mknod "${node}" b ${MAJOR} ${minor##*md} &> /dev/null
	done
}

# Start software raid with raidtools (old school)
if [[ -x /sbin/raidstart && -f /etc/raidtab ]] ; then
	devs=$(awk '/^[[:space:]]*raiddev/ { print $2 }' /etc/raidtab)
	if [[ -n ${devs} ]] ; then
		create_devs ${devs}
		ebegin "Starting up RAID devices (raidtools)"
		output=$(raidstart -aq 2>&1)
		ret=$?
		[[ ${ret} -ne 0 ]] && echo "${output}"
		eend ${ret}
	fi
fi

# Start software raid with mdadm (new school)
mdadm_conf="/etc/mdadm/mdadm.conf"
[[ -e /etc/mdadm.conf ]] && mdadm_conf="/etc/mdadm.conf"
if [[ -x /sbin/mdadm && -f ${mdadm_conf} ]] ; then
	devs=$(awk '/^[[:space:]]*ARRAY/ { print $2 }' ${mdadm_conf})
	if [[ -n ${devs} ]] ; then
		create_devs ${devs}
		ebegin "Starting up RAID devices (mdadm)"
		output=$(mdadm -As 2>&1)
		ret=$?
		[[ ${ret} -ne 0 ]] && echo "${output}"
		eend ${ret}
	fi
fi

# vim:ts=4