DEVICES="/dev/sda /dev/sdb"
RAIDLEVEL=1
mdadm --detail /dev/md*|grep 'Version : 1.0' >& /dev/null || (
lvm vgchange -a n
mdadm -S -s
NUMDEVS=$(for dev in $DEVICES; do
   echo wipefs -a -f $dev
done|wc -l)
for dev in $DEVICES; do
   mdadm --zero-superblock $dev
   wipefs -a -f $dev
done
# must use older metadata format to leave disks looking normal for uefi
mdadm -C /dev/md/raid $DEVICES -n $NUMDEVS -e 1.0 -l $RAIDLEVEL -b internal
# shut and restart array to prime things for anaconda
mdadm -S -s
mdadm --assemble --scan
)
while :; do
    # newer mdraid verions might have <hostname>:<raidname>
    TARGET_RAID=$(ls /dev/md/raid /dev/md/*:raid 2>/dev/null | head -n 1)

    [ -n "$TARGET_RAID" ] && break

    echo 'Waiting on array to be linked...'
    sleep 0.5
done

# Extract the underlying block device name (e.g., md127) using the captured path
readlink "$TARGET_RAID" | sed -e 's/.*\///' > /tmp/installdisk
