|
|
| |
[[ -f /proc/mdstat ]] || exit 0 | [[ -f /proc/mdstat ]] || exit 0 |
| |
# We could make this dynamic, but eh |
# MAJOR for md (non-partitioned) is normally static, 9. |
#[[ -z ${MAJOR} ]] && export MAJOR=$(awk '$2 == "md" { print $1 }' /proc/devices) |
# MAJOR for mdp (partitioned) is normally dynamic, but often 254. |
MAJOR=9 |
# 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() { | 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 | for node in $@ ; do |
|
# Prefix /dev/ if necessary. |
[[ ${node} != /dev/* ]] && node=/dev/${node} | [[ ${node} != /dev/* ]] && node=/dev/${node} |
[[ -e ${node} ]] && continue |
|
|
|
dir=${node%/*} |
|
[[ ! -d ${dir} ]] && mkdir -p "${dir}" |
|
| |
minor=${node##*/} |
# Split out devdir and devfile, create devdir if necessary. |
mknod "${node}" b ${MAJOR} ${minor##*md} &> /dev/null |
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 | done |
} | } |
| |