From 7d7f001826128519010a0c7dfb9207f2167c18ea Mon Sep 17 00:00:00 2001 From: Markus Hilger Date: Fri, 22 May 2026 02:00:41 +0200 Subject: [PATCH] Handle hostname-prefixed md device names and clear stale superblocks Newer mdadm versions may load arrays under names like `/dev/md/:raid` after reboot instead of `/dev/md/raid`. Detect both naming schemes when waiting for the array device and use the resolved path consistently when determining the underlying md device name. Also clear existing md superblocks before wiping signatures to avoid stale RAID metadata interfering with array creation or assembly. --- misc/swraid | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/misc/swraid b/misc/swraid index bb176a3f..e7860d47 100644 --- a/misc/swraid +++ b/misc/swraid @@ -7,6 +7,7 @@ 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 @@ -15,9 +16,15 @@ mdadm -C /dev/md/raid $DEVICES -n $NUMDEVS -e 1.0 -l $RAIDLEVEL -b internal mdadm -S -s mdadm --assemble --scan ) -while [ ! -e /dev/md/raid ]; do +while :; do + # newer mdraid verions might have : + 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 -readlink /dev/md/raid|sed -e 's/.*\///' > /tmp/installdisk +# Extract the underlying block device name (e.g., md127) using the captured path +readlink "$TARGET_RAID" | sed -e 's/.*\///' > /tmp/installdisk