--- raid-start.old.sh 2006-04-26 10:07:51.000000000 -0700 +++ raid-start.sh 2006-05-16 04:12:28.000000000 -0700 @@ -5,22 +5,64 @@ [[ -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 +# 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 +# Try to make sure the devices exist before we use them. create_devs() { - local node dir minor + 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} - [[ -e ${node} ]] && continue - - dir=${node%/*} - [[ ! -d ${dir} ]] && mkdir -p "${dir}" - minor=${node##*/} - mknod "${node}" b ${MAJOR} ${minor##*md} &> /dev/null + # 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 }