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

    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    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.......

    Code:
    #!/bin/sh
    #
    # 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)
    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
    # where s0 - / and s1 - swap and s3 - /usr
    SLICES="s0 s3"
    
    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/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
    do
    	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;
    		mv ${MOUNTDIR}/${SCRIPT} ${MOUNTDIR}/${SCRIPT}.DONTRUN;
    	fi
    umount ${MOUNTDIR}
    done
    
    echo 
    echo Disk Copy script ended `date`
    echo =====================================
    echo


    Thanks.


    Larry
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,394
    Rep Power
    1688
    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