#!/bin/sh

. /lib/partman/lib/base.sh

# Load modules and scan arrays if it was not done before
if [ -e /proc/mdstat ] && [ -d /dev/md ]; then
	exit 0
fi

# Try to load the necessary modules.
depmod -a >/dev/null 2>&1
modprobe md-mod >/dev/null 2>&1

# Try to detect MD devices, and start them
# mdadm will fail if /dev/md does not already exist
mkdir -p /dev/md

log-output -t md-devices --pass-stdout \
	mdadm --examine --scan --config=partitions >/tmp/mdadm.conf

log-output -t md-devices \
	mdadm --assemble --scan --run --config=/tmp/mdadm.conf --auto=yes

exit 0
