#!/usr/bin/ksh ################################################# # # # # Changed: 8/27/2007 - vfstab is updated when mirrors are created. # Reboot will mount the mirrored devices. Then final step # is to run the script again with a '-a' to attach the mirrors. # Create Solaris Volumes and mirrors... # Assumptions: Two Indentical disks # System defined disk0 and disk1 will be used # This script will mirror currently mounted disks. # Modify this as needed... # Note: The meta devices used will be: # d1# = Primary disk # d2# = Secondary/Mirror disk # d3# = Mirrored Metadevice # # i.e. d10 = /dev/dsk/c1d0s0 = / # d20 = /dev/dsk/c1d1s0 = / mirror # d30 = /dev/dsk/d30 mounted as / # # Note: This script must run twice. Once/First time # setup of the metadevices the second time {after a reboot} # attaches the mirrored devices. # # Works on both Sparc and X86 Hardware. # #======================================================== #Get boot drive #======================================================== Slices=`grep \/dev\/dsk /etc/vfstab | awk '{print $1}' | awk -F/ '{print $4}' | awk -Fs '{print $2}'` echo | format > /tmp/format.out bootdrive=`/usr/bin/cat /tmp/format.out | /usr/bin/grep " 0\." | /usr/bin/awk '{print $2}' ` bootdrive2=${bootdrive}s2 /usr/bin/echo "Boot drive = " $bootdrive $bootdrive2 #======================================================== ##Get drive to mirror #======================================================== mirrordrive=`/usr/bin/cat /tmp/format.out | /usr/bin/grep " 1\." | /usr/bin/awk '{print $2}' ` mirrordrive2=${mirrordrive}s2 /usr/bin/echo "Mirror drive = " $mirrordrive $mirrordrive2 #======================================================== ##Get boot and mirror device info for eeprom #======================================================== bootdevice=`ls -al /dev/rdsk/$bootdrive2 | awk '{print $11}' | sed -e
's/\.//g' | sed -e 's/\/\///g' | sed -e 's/sd/disk/g' | sed -e 's/devices\///g' | sed -e 's/\:c\,raw/\//g' ` mirrordevice=`ls -al /dev/rdsk/$mirrordrive2 | awk '{print $11}' | sed -e 's/\.//g' | sed -e 's/\/\///g' | sed -e 's/sd/disk/g' | sed -e 's/devices\///g' | sed -e 's/\:c\,raw/\//g' ` #echo $bootdevice #echo $mirrordevice if [ "$1" != "-a" ] then printf "\nAdd additional slices? y/n: " read answer if [ "$answer" = "y" -o "$answer" = "Y" ] then printf "Enter slice(s) [space delimited]: " read newslice Slices=${Slices}" $newslice" echo $Slices fi printf "Enter metadb slice: " read metadbslice if [ "$metadbslice" ] then echo "Metadb will be installed onto slice $metadbslice" else metadbslice=7 # Default slice for metadb. fi #======================================================== #Display current disks to be used #======================================================== printf "\nContinue... [y/n] -: " read x if [ "$x" = "y" -o "$x" = "Y" ] then printf "Here we go!! \n\n" else exit fi #======================================================== #Make sure you really want run this again #======================================================== fi if [ -f /root/mksvm.mark ] then printf "\n\nAlready ran $0 once want to run it again? y/n : " read x if [ $x = y -o $x = Y ] then echo " "
else
exit
fi
else touch /root/mksvm.mark [ "$1" != "-a" ] && printf "Remember to run mksvm.sh -a to attach and sync mirrors.\n" fi #======================================================== ##Duplicate bootdisk layout with mirror drive ##Attach mirrors... #======================================================== if [ "$1" = "-a" ] then echo "Attaching the second submirror... Please wait..." echo "Installing boot loader to mirror drive." if [ `uname -m` = "i86pc" ] then /sbin/installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/${mirrordrive}s0 else /usr/sbin/installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/${mirrordrive}s0 fi if [ -f /etc/vfstab.new ] then rm /etc/vfstab.new fi Mirrors=`/usr/sbin/metastat | grep Mirror | awk '{print $1}' | sed s/d//g | sed s/://g | sed s/0//g` echo "Attaching mirrors for slices= "$Mirrors for slice in `echo "$Mirrors"` do metattach d${slice} d2${slice} done # Need to attach root / vol manually metattach d0 d20 echo "Checking status of mirrors..." metastat | grep Resync if [ then echo else echo echo echo
`uname -m` = "i86pc" ] "Platform is x86 skipping eeprom changes." "Creating aliases for boot disk and mirror" "devalias rootdisk /"$bootdevice > /root/nvramrc "devalias rootmirror /"$mirrordevice >> /root/nvramrc
eeprom "boot-device=rootdisk rootmirror" eeprom "use-nvramrc?=true" eeprom "nvramrc=`cat /root/nvramrc`" eeprom boot-device eeprom use-nvramrc? eeprom nvramrc fi exit else # Duplicating layout of rootdisk to mirrordisk printf "Setting up disk layouts for mirror drive.\n" prtvtoc /dev/rdsk/$bootdrive2 | fmthard -s - /dev/rdsk/$mirrordrive2 # Create Databases two copies on each drive metadb -a -f -c3 /dev/dsk/${bootdrive}s${metadbslice} metadb -a -f -c3 /dev/dsk/${mirrordrive}s${metadbslice} # Create SVM devices for the following slices AllSlices=`prtvtoc /dev/rdsk/$bootdrive2 | tail -6 | grep . | awk '{print $1}' | grep -v 2` MountedVols=`df -hl | grep dev | grep dsk | egrep -v "rmdisk|cdrom" | awk '{print $NF}'` echo "Creating mirrors on slice" $Slices echo "for" $MountedVols "filesystems." for slice in $Slices do metainit -f d1${slice} 1 1 ${bootdrive}s${slice} metainit -f d2${slice} 1 1 ${mirrordrive}s${slice} metainit d${slice} -m d1${slice} done # Verify changes sleep 10 mirnum=`metastat | grep Mirror | wc -l` if [ "$mirnum" -ge `echo "$Slices" | wc -l` ] then echo "$mirnum mirrors have been created" fi sleep 3 metaroot d0 metainit hsp001 lockfs -fa ls -l /dev/rdsk/${mirrordrive2} echo " " cp /etc/vfstab /etc/vfstab.original cp /etc/vfstab /etc/vfstab.orig cp /etc/vfstab /etc/vfstab.bak for slice in `echo "$Slices"` do
/usr/bin/perl -pi -e "s/${bootdrive}s${slice}/d${slice}/g;" /etc/vfstab done /usr/bin/perl -pi -e "s/\/dev\/dsk/\/dev\/md\/dsk/g;" /etc/vfstab /usr/bin/perl -pi -e "s/\/dev\/rdsk/\/dev\/md\/rdsk/g;" /etc/vfstab echo "Updating the /etc/system file to allow booting when boot/mirror device is down." echo "* This entry below is necessary to boot when boot/mirror device has failed." >> /etc/system echo "set md:mirrored_root_flag=1" >> /etc/system echo "* Set these to increase performance in SVM" >> /etc/system echo "set md_mirror:md_resync_bufsz=1024" >> /etc/system echo "set maxphys=1048576" >> /etc/system echo "set md:md_maxphys=1048576" >> /etc/system printf "Enter y to reboot or n to exit." read x if [ then echo echo echo echo echo echo echo
"$x" = "Y" -o "$x" = "y" ] "Rebooting... Please stand by..." "You must attach the second submirror after rebooting. i.e.:" "metattach d0 d20" "metattach d3 d23" "metattach d4 d24" "metattach d5 d25" "metattach d6 d26"
echo "To auto-attach mirrors and setup rootmirror for booting run this $0 again with -a switch." echo "i.e. $0 -a" sleep 15 init 6 else clear echo "Updating the /etc/system file to allow booting when boot/mirror device is down." echo "* This entry below is necessary to boot when boot/mirror device has failed." >> /etc/system echo "set md:mirrored_root_flag=1" >> /etc/system echo "You must reboot for changes to be activated!" fi fi