How To Detach Mirror in Solaris – Script

How to detach mirror disks in Solaris? Assuming we us SVM, we normally do this like this, manually:

metastat -c d0 (verify disk components)
eeprom bood-device (further verify the boot disk)
metadetach rootdev detachdevice

or put it a script for repetitive use and to avoice typo mistakes:

cat detach_mirror.ksh

rootdev=`df -k /|tail -1|awk '{print $1}'|cut -d"/" -f5`
bootdisk=`eeprom boot-device|cut -d"=" -f2|awk '{print $1}'`

if [[ $bootdisk = "disk" || $bootdisk = "disk0" ]]; then
detachdev=`metastat -p $rootdev|tail -2|grep -v "t0d0"|awk '{print $1}'`
elif [[ $bootdisk = "disk1" ]]; then
detachdev=`metastat -p $rootdev|tail -2|grep -v "t1d0"|awk '{print $1}'`
elif [[ $bootdisk = "disk2" ]]; then
detachdev=`metastat -p $rootdev|tail -2|grep -v "t2d0"|awk '{print $1}'`
echo "Unknown disk to detach"

echo "boot-disk is $bootdisk"
echo "root device is $rootdev"
echo "\nmetastat -p $rootdev"
metastat -p $rootdev

echo "\ncommands:"
echo "sync; metadetach $rootdev $detachdev"
echo "sleep 10"

detachdiskname=`metastat -p $detachdev|awk '{print $NF}'`
echo "mkdir /a"
echo "mount /dev/dsk/$detachdiskname /a"
echo "cp -p /a/etc/vfstab /a/etc/"

#echo awk '$1=="/dev/md/dsk/'$rootdev'" {print "/dev/dsk/'$detachdiskname'\t/dev/rdsk/'$detachdiskname'\t"$3"\t"$4"\t"$5"\t"$6"\t"$7; next} {print}' /etc/vfstab
echo "awk '\$1==\"/dev/md/dsk/$rootdev\" {print \"/dev/dsk/$detachdiskname\\\t/dev/rdsk/$detachdiskname\\\t\"\$3\"\\\t\"\$4\"\\\t\"\$5\"\\\t\"\$6\"\\\t\"\$7; next} {print}' /etc/vfstab" \> /a/etc/vfstab
echo "egrep -v \"rootdev.*md|MDD root info\" /etc/system > /a/etc/system"

echo "\ncd /"
echo "umount /a"
echo "rmdir /a"

Leave a Reply

Your email address will not be published. Required fields are marked *