#!/bin/ksh # #set -x # ######################################################################## #DiskSuite mirror shell script ######################################################################## # #*************************************************** # critical - select the right two target disks #*************************************************** BOOT_DISK=c0t0d0 MIRROR_DISK=c1t0d0 #BOOT_DISK=c1t0d0 #MIRROR_DISK=c1t1d0 #BOOT_DISK=c1d0 #MIRROR_DISK=c2d0 ######################################################################## #If slice 0 is not your root slice, make sure to modify the script so #that the $METAROOT command is executed on the root slice. #Normally slice 0 is, unless you did a liveupgrade and are running off #the alt root slice (usually slice 3). ######################################################################## # #Be sure to comment out slices that you would not like mirrored. #The script assumes that SVM/DiskSuite database replicas are located #on slice 4, so this slice should reamain commented out. # # Steps # 1: setup partition table that has your slices AND a 20MB slice 4 # (or whatever you make the database on) # 2: select correct two DISKS Variables in following section # 3: edit this script to add/delete slices/partitions to mirror # 4: make sure /var/tmp is its own directory (not a /tmp link) # if it is, then make a /mydir and put this file in it and # modify this file/script to look in /mydir and not /var/tmp # 5: run this script # 6: check /etc/vfstab for /dev/md/dsk/d0 for "/" (root) # 7: reboot # 8: run this script again # 9: modify /etc/vfstab for the other partitions affected and insert # "/md" in their two disk path fields # /dev/dsk/xxx /dev/rdsk/xxx ...... # becomes # /dev/md/dsk/xxx /dev/md/rdsk/xxx ...... # 10: remount affected partitions OR reboot # 11: done # ######################################################################## if [[ -e /usr/sbin/prtdiag ]] then PRTDIAG=/usr/sbin/prtdiag else PRTDIAG=/usr/platform/$(uname -m)/sbin/prtdiag fi if [[ -n $($PRTDIAG | grep 1030 | grep -i LSI ) && -e /usr/sbin/raidctl ]] then print "*** You have a hardware RAID controller - better than software SVM ***" print "The recommended action is to use hardware instead of SVM RAID." print "Meaning you should answer 'no' to the following." print "" print "Do you want to continue with this SVM program? [y,n]" read ANS if [[ -n $(print $ANS | grep -i ^y) ]] then print "Quitting." print "Use: /usr/sbin/raidctl -c $BOOT_DISK $MIRROR_DISK" exit 5 else print "Continuing." sleep 2 fi fi #***************************************** # # if you change from s4 for meta, change # it later on in the script when it mirrors # DB_SLICE=s4 METAINIT=/usr/sbin/metainit METAROOT=/usr/sbin/metaroot METATTACH=/usr/sbin/metattach # # file for correct phase (1 - root, 2 - rest) # FLAGFILE=/var/tmp/disksuite.phase1 # # file to make sure a reboot was done # FLAGFILE_REBOOT=/tmp/disksuite.phase1-reboot if [[ -f $FLAGFILE_REBOOT ]] then print "" print "*** IMPORTANT WARNING ***" print "Must reboot the system before we can continue." print "Disksuite requires this." print "" # no flag file and no metadevices elif [[ ! -f $FLAGFILE && -z "$(awk '/md/ {if ($3 == "/") print $0}' /etc/vfstab)" ]] then #make the rootmirror the same as the rootdisk prtvtoc /dev/rdsk/${BOOT_DISK}s0 | fmthard -s - /dev/rdsk/${MIRROR_DISK}s0 # # different boot loaded depending on architecture # if [[ $(uname -p) == "sparc" ]] then # Make the boot disk bootable installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk \ /dev/rdsk/${BOOT_DISK}s0 # Make the mirror disk bootable installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk \ /dev/rdsk/${MIRROR_DISK}s0 elif [[ $(uname -p) == "i86pc" ]] then # Make the boot disk bootable - writes MBR to both disks installgrub /boot/grub/stage1 \ /boot/grub/stage2 /dev/rdsk/${BOOT_DISK}s0 # Make the mirror disk bootable - writes MBR to both disks installgrub /boot/grub/stage1 \ /boot/grub/stage2 /dev/rdsk/${MIRROR_DISK}s0 else print "ERROR: Unknown architecture (uname -p)" exit 5 fi metadb -a -f -c3 /dev/dsk/${BOOT_DISK}${DB_SLICE} \ /dev/dsk/${MIRROR_DISK}${DB_SLICE} if (( $? )) then print "ERROR: must have a 20MB /dev/dsk/${BOOT_DISK}${DB_SLICE}" exit 2 fi # Slice 0 (root slice) $METAINIT -f d10 1 1 ${BOOT_DISK}s0 $METAINIT -f d20 1 1 ${MIRROR_DISK}s0 $METAINIT d0 -m d10 $METAROOT d0 sync lockfs -fa sleep 3 touch $FLAGFILE touch $FLAGFILE_REBOOT # # # print "" print "*** IMPORTANT WARNING ***" print "" print "Make sure /etc/vfstab has for root mount : /dev/md/dsk/d0" print "*** Make this check now. ***" print "" print "*** then reboot NOW --- ASAP ***" print "" # flag file exists and root is setup w/ md elif [[ -f $FLAGFILE && -n "$(awk '/md/ {if ($3 == "/") print $0}' /etc/vfstab)" ]] then $METATTACH d0 d20 # Slice 1 (swap) $METAINIT -f d11 1 1 ${BOOT_DISK}s1 $METAINIT -f d21 1 1 ${MIRROR_DISK}s1 $METAINIT d1 -m d11 $METATTACH d1 d21 # Slice 2 will not be mirrored (represents entire disk) # Slice 3 $METAINIT -f d13 1 1 ${BOOT_DISK}s3 $METAINIT -f d23 1 1 ${MIRROR_DISK}s3 $METAINIT d3 -m d13 $METATTACH d3 d23 # Slice 4 # DO NOT mirror: metadb slices (two copies managed by LVM/disksuite) #### $METAINIT -f d14 1 1 ${BOOT_DISK}s4 #### $METAINIT -f d24 1 1 ${MIRROR_DISK}s4 #### $METAINIT d4 -m d14 #### $METATTACH d4 d24 # Slice 5 $METAINIT -f d15 1 1 ${BOOT_DISK}s5 $METAINIT -f d25 1 1 ${MIRROR_DISK}s5 $METAINIT d5 -m d15 $METATTACH d5 d25 # Slice 6 $METAINIT -f d16 1 1 ${BOOT_DISK}s6 $METAINIT -f d26 1 1 ${MIRROR_DISK}s6 $METAINIT d6 -m d16 $METATTACH d6 d26 # Slice 7 $METAINIT -f d17 1 1 ${BOOT_DISK}s7 $METAINIT -f d27 1 1 ${MIRROR_DISK}s7 $METAINIT d7 -m d17 $METATTACH d7 d27 rm $FLAGFILE if [[ $(uname -m) == "i86pc" ]] then print "You are on x86 architecture. " print "You must set the eeprom altbootpath=\"\"" print "And then add this to the /boot/solaris/bootenv.rc file" print "I will try and set it for you" set -x DEVPATH=$(eeprom bootpath | awk -F= '{print $2}') ALTDEVPATH_TEMP="$(format < /dev/null | grep DEFAULT | sed -n 2p \ | awk '{print $2}')s0" ALTDEVPATH=$(ls -l /dev/dsk/$ALTDEVPATH_TEMP \ | awk -F\> '{print $2}' | cut -c15-) eeprom bios-boot-device=$DEVPATH eeprom altbootpath=$ALTDEVPATH if [[ -z $(grep -w altbootpath /boot/solaris/bootenv.rc) ]] then print "setprop altbootpath '$ALTDEVPATH'" >> /boot/solaris/bootenv.rc fi set +x fi print "Done." print "" print "YOU must modify the /etc/vfstab to reflect the new md devices and paths." print "i.e. /dev/rdsk/cXtXdXs1 with /dev/md/dsk/d1" print "" print "Also, you should do a 'dumpadm -d /dev/md/dsk/s1' for the new swap device." print "" # no flag file exists BUT there are metadevices else print "" print "You must get the metadb done first." print "This script did not run the first pass correctlly - please review." print "This script took NO ACTION on this run." print "" fi