Gadget Review: D-Link DNS-321 NAS
August 1, 2010 – 10:51 am | No Comment

The D-Link DNS-321 is among the least expensive dual-disk RAID NAS systems currently on the market. This small device offers an impressive array of features such as FTP, Samba, NFS, iTunes, DHCP, HTTP and UPnP …

Read the full story »
Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands and Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Disks and Volumes, Scripts

Solaris boot disk copy

Submitted by admin on November 20, 2005 – 2:24 amOne Comment
Solaris boot disk copy

The following script will duplicate a Solaris boot disk. The script uses ufsdump/restore as opposed to dd, so disks of different sizes can be used.

#!/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\/[^      ]*\).*/\1r\2/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

Popularity: 19% [?]

Related posts

One Comment »

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.