# /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.4 2005/06/10 02:09:28 vapier Exp $ [[ -f /proc/mdstat ]] || exit 0 # MAJOR for md (non-partitioned) is normally static, 9. # MAJOR for mdp (partitioned) is normally dynamic, but often 254. # Hard define md for backward compatibility. Comment hard define of mdp. MAJOR_MD=9 #MAJOR_MDP=254 # If the majors are commented above, this should define them (/proc must be mounted) [[ -z ${MAJOR_MD} ]] && MAJOR_MD=$(awk '$2 == "md" { print $1 }' /proc/devices) [[ -z ${MAJOR_MDP} ]] && MAJOR_MDP=$(awk '$2 == "mdp" { print $1 }' /proc/devices) # Try to make sure the devices exist before we use them. create_devs() { local node devdir devfile minor major partnum partnode partnodes # This scans in the list of mdp nodes from fstab, to be used in the loop below. partnodes=$(awk '/^\/dev\/([^ ]*\/)?md_d/ { print $1 }' /etc/fstab) for node in $@ ; do # Prefix /dev/ if necessary. [[ ${node} != /dev/* ]] && node=/dev/${node} # Split out devdir and devfile, create devdir if necessary. devdir=${node%/*} devfile=${node##*/} [[ ! -d ${devdir} ]] && mkdir -p "${devdir}" # Setup major, minor. if [[ ${devfile#md_d} != ${devfile} ]]; then major=${MAJOR_MDP} minor=${devfile##*md_d} # Due to partition minors, mdp minors are 64-spaced. let minor=minor*64 else major=${MAJOR_MD} minor=${devfile##*md} fi # Create the node, if necessary. [[ ! -e ${node} ]] && mknod "${node}" b ${major} ${minor} &> /dev/null # For mdp, we may need to create partition nodes too. if [[ ${major} -eq ${MAJOR_MDP} ]]; then # Loop thru partnodes (scanned in from fstab outside the loop). for partnode in $partnodes; do # Split out the partfile. partfile=${partnode##*/} # If partition on mdp devfile being processed... if [[ ${partfile%p*} = ${devfile} ]]; then # ... split out the partnum, add to it the mdp minor, and... partnum=${partfile##md_d*p} let partnum=partnum+minor # ... create the partition devnode, if necessary. [[ ! -e ${partnode} ]] && mknod "${partnode}" b ${major} ${partnum} fi done fi 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) if [[ -x /sbin/mdadm && -f /etc/mdadm.conf ]] ; then devs=$(awk '/^[[:space:]]*ARRAY/ { print $2 }' /etc/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