Re: mdadm and UUIDs for its component drives
Hi Luke,
Luke Kenneth Casson Leighton wrote:
 the answer is that mdadm tracks down the hardlink and displays, as
best i can tell, only that, with no immediately obvious options to get
it to display the disk UUIDs.
I hear what you are saying, but I had a related problem which was similar.
When starting up a machine with two external 2TB drives which had been 
set up as a mirror, it would sometimes only find one drive and then it 
would happily mount the RAID1 array in a degraded state.  Then, when the 
other drive was added in, it had to do a rebuild of the array.  It's not 
much good having to rebuild the array after each boot when the mirror 
should be perfectly fine.
So I solved it by adding the following to my /etc/rc.local
nohup /usr/local/bin/u1-mirror-drive.sh 2>&1 >/dev/null &
Note that external mirror drive, which mounts at /u1, has this 
/etc/fstab entry:
/dev/mapper/vg--external--1-vg--external--1--u1   /u1             ext4 
      noauto,rw         0       0
I've masked the UUID below, but I don't see how it could cause any 
trouble if I did not do that.....
The RAID1 is identified ONLY with UUID in /etc/mdadm/mdadm.conf
#  grep ARRAY /etc/mdadm/mdadm.conf
ARRAY /dev/md0 UUID=06fd3d46-XXXX-XXXX-YYYY-ZZZZZZZZZZZZ
Here's my script that handles getting everything working after a boot:
#  cat /usr/local/bin/u1-mirror-drive.sh
#!/bin/bash
RAID_DRIVE_ID=06fd3d46-XXXX-XXXX-YYYY-ZZZZZZZZZZZZ
RAID_DRIVES=2
TIME_LIMIT=60
echo RAID Drive ID: $RAID_DRIVE_ID
echo Number of Devices required: $RAID_DRIVES
echo Time Limit: $TIME_LIMIT
function error_drive_missing ()
{
        echo
        echo -en "\aMissing drive(s) ... cannot assemble /dev/md0\n\n"
        /sbin/blkid|/bin/grep $RAID_DRIVE_ID
        exit
}
(
echo "=================="
echo -en "Waiting for $RAID_DRIVES drives to be visible for 
\"linux_raid_member(s)\" with blkid of: \"$RAID_DRIVE_ID\" ... \n\t"
CNT=1
echo -en "00"
while [ $(/sbin/blkid|/bin/grep $RAID_DRIVE_ID|/usr/bin/wc -l) -lt 
$RAID_DRIVES ]
do
        if [ $CNT -lt 10 ]; then echo -en "\b$CNT"; else echo -en 
"\b\b$CNT";fi
        if [ $CNT -eq $TIME_LIMIT ]; then echo -en "\b\b$TIME_LIMIT 
seconds ....\n";error_drive_missing;fi
        CNT=$(($CNT + 1))
        /bin/sleep 1
done
echo -en "\n\nAll required drives found in $CNT seconds....\n"
echo "=================="
echo -en "\n\n"
cmds='/sbin/mdadm --assemble /dev/md0~
/sbin/vgscan~
/sbin/vgchange -ay vg-external-1~
/bin/mount /u1~
/bin/mount~
/bin/df -Th~
/bin/date~
/sbin/mdadm -D /dev/md0~
/bin/cat /proc/mdstat'
echo ".................."
IFS='~'
echo $cmds|
while read cmd
do
        IFS=$' \t\n'
        echo "=================="
        echo "${cmd}"
        echo "------------------"
        $cmd
        echo -en "==================\n\n"
done
echo ".................."
) 2>&1 | /usr/bin/tee /var/log/md0-vg-external-1-u1-wrk.$(date 
+%Y%m%d%H%M).out
Right now, I am using 2x 2TB drives as mirrors, I plan to add a 3rd 
drive as a 3-way mirror and to let it sync up, then remove the drive for 
off-site storage.  A 4th drive will come into play as well to rotate 
off-site storage.  Consequently, I catered for that scenario in the 
"mount" script above -- ie I can easily change the number of RAID 
devices to find before continuing if I choose to have more online or not 
during boot.  The script gives up if it cannot find the required number 
of devices within 60 seconds, then I will have to manually intervene.
As you can see from the script, there is some logging taking place so 
that I can check things over if necessary.
I may end up using multiple external mirrors at some stage; if I do that 
then I'll likely have duplicated scripts for each metadevice and the 
scripts will be [slightly] modified as required.  I may end up with a 
parameter file with a single script, but it's probably not worth the 
further effort.  Although using command line variables would be an easy 
and viable option.
Anyway.... the long and short of it is, I can use mdadm without regard 
to what devices are found, such as /dev/sda /dev/sdb /dev/sdc and the 
like as I rely purely on the UUID functionality, which as you know, 
mdadm handles perfectly well.  ;-)
--
Kind Regards
AndrewM
Andrew McGlashan
Broadband Solutions now including VoIP
Reply to: