1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Rep Power

    Help with script to copy drive with cpio

    I found this script on the internet for my brother to use when copying his
    Sun Box 20 Gig Hard Drive to a new 120 Gig Seagate. The script doesn't
    traverse subdirectories, and therefore doesn't copy the 20 Gig to the
    120 Gig drive. If someone could assist with the script to help getting it
    to function with cpio to copy the 20 Gig to the 120 Gig I'd appreciate it,
    as I know nothing about Unix.......

    # Original Script written by Constantin Ionescu
    # Modified by Carlo Cosolo
    # Modified by Peter Baer Galvin
    # Modified by John West
    # <<<----- Modified for use of cpio instead of ufsdump/ufsrestore
    # 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)
    # The empty disk to duplicate it to (leave off slice numbers and path)
    # The directory to mount destination partitions on while duplicating
    # The file name of this script, to rename it on the destination to avoid execution
    # The slices that should be copied
    # where s0 - / and s1 - swap and s3 - /usr
    SLICES="s0 s3"
    echo ===================================
    echo Disk Copy script started `date`
    # Make sure the mount point for duplicate partitions exists
    if [ ! -d $MOUNTDIR ]; then
    mkdir $MOUNTDIR
    chmod 700 $MOUNTDIR
    # Partition the duplicate disk, make filesystems, make it bootable
    prtvtoc /dev/dsk/${SRC}s2 | fmthard -s - /dev/rdsk/${DEST}s2
    # Less elegant, but working version of line above
    # 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
    	newfs /dev/dsk/${DEST}${fs} < /dev/null; mount /dev/dsk/${DEST}${fs} ${MOUNTDIR};
    	find /dev/dsk/${SRC}${fs} -mount -print | cpio -pdmuV ${MOUNTDIR};
    	if [ $fs = "s0" ]; then
    		sed 's/${SRC}/${DEST}/g' /etc/vfstab > ${MOUNTDIR}/etc/vfstab;
    umount ${MOUNTDIR}
    echo Disk Copy script ended `date`
    echo =====================================


  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Rep Power
    Your major problem, or one of them at least, is in the copying of the disk layout from source to target. Doing this is a good idea if the disks are the same, but doing so going from a 20GB disk to a 120GB disk means you end up with the second disk only being setup' to be 20GB. You can go back later and mess with the partitions to resize them, but tread carefully. It's been a while since I messed with disks in Solaris and I was wary even when I thought I knew what I was doing!

    Whilst the script duplicates the disk layout from source to target it only copies whatever is mounted on sections 0 and 3 (root and usr I think are the defaults for those). Section 1 tends to be swap (generally don't copy that!), section 2 is 'whole disk' - great to backup entire disk if you are using dd or something similar, sections 4, 5, 6 and 7 - if used - would be for stuff like /var, /home (or /export/home), etc.
    I have not used cpio a great deal, but that looks like it would deal with directories, so long as they are within the file system (partition) being copied.
    If there are other mounted file systems on the source disk you'll want to include the section names in the variable SLICES.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo