#!/bin/sh # Original Script written by Constantin Ionescu # Modified by Carlo Cosolo # Modified by Peter Baer Galvin # Modified by John West # Modified by Shawn Laemmrich # Modified by Joshua Myles # Use and distribute freely PATH=/usr/bin:/usr/sbin export PATH # the root disk to duplicate (example: c0t0d0) SRC=c0t0d0 # the empty target disk (example: c0t1d0) DEST=c0t1d0 # the directory to mount target partitions while duplicating MOUNTDIR=/dup_0 # the path and file name of this script (relative to the slice it's on) SCRIPT=local/sbin/mirror # the slices to be copied (example: "s0 s3 s4 s6") SLICES="s0 s3 s4 s5 s6" # the slice on which /etc/vfstab resides VFSTAB_SLICE=s0 # the slice on which this script resides SCRIPT_SLICE=s6 echo \*\*\* Disk mirror started `date` \*\*\* echo # make sure the mount point exists if [ ! -d $MOUNTDIR ]; then mkdir $MOUNTDIR chmod 700 $MOUNTDIR fi # get disk geometry and partition information prtvtoc /dev/rdsk/${SRC}s2 > /tmp/vtoc # copy information to source disk fmthard -s /tmp/vtoc /dev/rdsk/${DEST}s2 # make the target disk bootable installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/${DEST}s0 # format and copy slices for fs in $SLICES do echo echo \*\*\* Making filesystem on /dev/dsk/$DEST$fs \*\*\* newfs /dev/dsk/$DEST$fs < /dev/null; # mount slice for copying mount /dev/dsk/$DEST$fs $MOUNTDIR; echo echo \*\*\* ufsdumping to /dev/dsk/$DEST$fs \*\*\* ufsdump 0f - /dev/dsk/$SRC$fs | (cd $MOUNTDIR; ufsrestore rf -); if [ $fs = $VFSTAB_SLICE ]; then echo echo \*\*\* Fixing /etc/vfstab on /dev/dsk/$DEST$fs \*\*\* sed s/$SRC/$DEST/g /etc/vfstab > $MOUNTDIR/etc/vfstab; fi if [ $fs = $SCRIPT_SLICE ]; then # let's not try to run this script on the target disk mv $MOUNTDIR/$SCRIPT $MOUNTDIR/$SCRIPT.norun; fi umount $MOUNTDIR done # create a syslog entry logger -pdaemon.notice "disk mirror completed" echo echo \*\*\* Disk mirror ended `date` \*\*\*