Solaris boot disk copy
A handy script to copy boot (or any other) disk under Solaris. This script uses ufsdump/ufsrestore – unlike the usual dd approach – which allows to use two disks of different architecture, as long as the target disk has sufficient space to accommodate source partitions. This is very useful when upgrading from old disks to new, larger disks.
#!/bin/sh
EMAIL=admin@domain.com
SUBJECT="Boot disk copy on `hostname`"
if [ "$#" != 2 ] ; then
echo "usage: $0 sdisk tdisk"
echo "where: sdisk is the source disk (e.g. c0t0d0)"
echo " tdisk is the target disk (e.g. c0t1d0)"
echo "Note: Please omit slice numbers!"
exit 1
fi
format/dev/null 2>&1 && S=$1
format/dev/null 2>&1 && T=$2
if [ -z "$S" ] ; then
echo "ERROR: Source disk $1 does not exist -- exit!" ; exit 2
elif [ -z "$T" ] ; then
echo "ERROR: Target disk $2 does not exist -- exit!" ; exit 3
fi
clear ; echo "
ATTENTION: This script will copy the whole disk $S to $T
If this is NOT what you intended to do, abort
by pressing Ctrl-C now!
Are you ready now [N] ? c"
read ans mist ; echo ""
[ "$ans" != "J" -a "$ans" != "j" -a "$ans" != "Y" -a "$ans" != "y" ] && exit 1
prtvtoc /dev/rdsk/${S}s2|fmthard -s - /dev/rdsk/${T}s2 # copy VTOC
for i in `tail -r /etc/mnttab|grep /a|awk '{print $2}'` # make sure nothing is
do umount -f $i >/dev/null 2>&1 # mounted under /a ...
done
[ -d /a ] || mkdir /a # create /a if not here
SD=/dev/rdsk/$S ; TD=/dev/rdsk/$T # the raw disk devices
fs=`df -kl | grep `echo $SD | sed -e 's/rdsk/dsk/'` | grep /dsk/ | sed -e 's/^.*(s[0-9]* ).*/1/'` # fs on boot disk used
for i in $fs;do
echo "creating file system on ${TD}$i ...c"
echo y | newfs ${TD}$i >/dev/null 2>&1 ; echo "" # create filesystems
done
for i in $fs ; do # mount new disk under
echo "copying all data from slice $S$i to $T$i ..." # /a and copy all data
M=/a`df -kl|grep ${S}$i|awk '{print $6}'|sed -e 's!/$!!'`
F=`df -kl|grep ${S}$i|awk '{print $6}'` # from source disk
mount `echo ${TD}$i|sed -e 's/rdsk/dsk/'` $M # to target disk
( /etc/init.d/xntpd stop ; sleep 30 ; /etc/init.d/xntpd start ) &
ufsdump 0f - `fssnap -F ufs -o raw,bs=$M,unlink ${F}`| ( cd $M ; ufsrestore rf - ) >/dev/null 2>&1 # (using ufsdump
fssnap -F ufs -d ${F} >/dev/null 2>&1 # with UFS snapshot)
echo ""
done
# Okay, now let's make the new disk bootable:
installboot /usr/platform/`uname -m`/lib/fs/ufs/bootblk `df -kl /a | sed -ne 's/(/dev/)(dsk/[^ ]*).*/1r2/p'`
# and modify the mount entries in /etc/vfstab on new disk:
sed -e "s/${S}/${T}/g" /etc/vfstab > /a/etc/vfstab
# send e-mail
echo "Boot disk copy $S to $T complete on `hostname`" | mailx -s "$SUBJECT" $EMAIL
2 Comments »
1 Pingbacks »
-
[…] If you are looking to make a copy of the boot disk, check out this script. […]

This code is corrupted! All of the less-than characters (&) have been lost. The code-view feature is the same. Who know what else is wrong.
This is The erroe i am getting now after i did some reformat of Unused NTFS space in Win 7.
I am trying to copy from Live CD, but i am getting many Errors, like can not open Image. map file and etc. Now i am not able to use my lap top. last 3 days i am playing with linux with the Help of Yahoo Friends. Plz, help me now also..
What i must to do to get my Win and Linux back without reinstalling ?
I am not familiar With Linux terminal Command also..
This is my Hard Disk Structure;
/dev/sda1 66 MB FAT De Dell utility
/dev/sda2 * 105 GB NTFS 7 HPFS/NTFS
/dev/sda3 1 GB Linux 82 Swap / Solaris
/dev/sda4 3 gb EXT3 f Linux
/dev.sda5 10 GB EXT4 / 83 Linux
and so on……..
So plz help me