This script assumes that it is called
/opt/local/etc/rootcopy. Fundamentally, it performs the following
steps
(words
in capital letters are variables in the script):
It
makes MOUNTDIR, a mount point for the duplication, if it doesn't
already exist.
It
duplicates the SRC disk's partitions onto DEST disk.
It
makes DEST bootable.
It
does a newfs on each DEST partition.
It
does a ufsdump pipe to a ufsrestore for each partition.
On
the root DEST partition, it modifies /etc/vfstab to change each
mention of SRC to DEST.
On
the root DEST partition, it renames itself so it will not run
accidentally if you boot off of the DEST disk.
It
echoes some state information, for logging purposes.
The
fmthard command is very useful for duplicating the partitioning from
one disk to another. Unfortunately, it has sometimes
failed
to copy the partition information in testing (saying that Partition
0 not aligned on cylinder boundary). If this is the case
when
you run it, you'll need to manually duplicate the partition to your
copy disk before you run the script and remove the
fmthard
command from the script.
Without
further ado, the script:
#!/bin/sh
#
Original Script written by Constantin Ionescu
#
Modified by Carlo Cosolo
#
Modified by Peter Baer Galvin
#
Modified by John West
#
Use and distribute freely
#
Define variables for use in the script
#
! Important, these must be set correctly !
#
The root disk to duplicate (leave off slice numbers and path)
SRC=c0t0d0
#
The empty disk to duplicate it to (leave off slice numbers and path)
DEST=c0t1d0
#
The directory to mount destination partitions on while duplicating
MOUNTDIR=/dup_0
#
The file name of this script, to rename it on the destination to
avoid execution
SCRIPT=/opt/local/etc/rootcopy
#
The slices that should be copied
SLICES="s0
s3 s4 s6 s7"
echo
====================================
echo
Disk Copy script started `date`
echo
#
Make sure the mount point for duplicate partitions exists
if
[ ! -d $MOUNTDIR ]; then
mkdir
$MOUNTDIR
chmod
700 $MOUNTDIR
fi
#
Partition the duplicate disk, make filesystems, make it bootable
prtvtoc
/dev/rdsk/${SRC}s2 > /tmp/vtoc
fmthard
-s /tmp/vtoc /dev/rdsk/${DEST}s2
installboot
/usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/${DEST}s0
#
Modify the following loop to handle any special cases
for
fs in $SLICES
do
newfs
/dev/dsk/${DEST}${fs} < /dev/null; mount /dev/dsk/${DEST}${fs}
${MOUNTDIR};
ufsdump
0f - /dev/dsk/${SRC}${fs}|(cd ${MOUNTDIR}; ufsrestore rf -);
if
[ $fs = "s0" ]; then
sed
's/${SRC}/${DEST}/g' /etc/vfstab > ${MOUNTDIR}/etc/vfstab;
mv
${MOUNTDIR}/${SCRIPT} ${MOUNTDIR}/${SCRIPT}.DONTRUN;
fi
umount
${MOUNTDIR}
done
echo
echo
Disk Copy script ended `date`
echo
====================================
echo