Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Disk Cloning in Solaris

Disk Cloning in Solaris:

A few assumptions:
master disk: c0t0d0
\--> disk already configured and in use
alternate: c0t1d0
\--> disk not configured and will become a clone of master
configured slices: 0 1 3 4
\--> 0=/, 1=swap, 3=/usr, 4=/var
your path: PATH=/usr/sbin:/usr/bin
\--> your path must contain at least the above
disk geometry:
\--> the disk geometry of both devices should be the same or
you should be aware of the potential issues otherwise

1) use prtvtoc and fmthard to partition the second disk

prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2

2) newfs the slices on the second disk

echo "y" | newfs /dev/rdsk/c0t1d0s0


for i in 3 4 ; do echo "newfs /dev/rdsk/c0t1d0s${i}"
echo "y" | newfs /dev/rdsk/c0t1d0s${i} ; done

3) mount up the root slice, etc, of the alternate disk under /mnt

[ ! -d /mnt ] && mkdir /mnt


mount /dev/dsk/c0t1d0s0 /mnt

4) change directory to /mnt and mirror the master disk

cd /mnt ; ufsdump 0uf - /dev/dsk/c0t0d0s0 | ufsrestore rf -


rm restoresymtable
[ ! -d /mnt/usr ] && mkdir /mnt/usr
mount /dev/dsk/c0t1d0s3 /mnt/usr
[ ! -d /mnt/var ] && mkdir /mnt/var
mount /dev/dsk/c0t1d0s4 /mnt/var
cd /mnt/usr ; ufsdump 0uf - /dev/dsk/c0t0d0s3 | ufsrestore rf -
rm restoresymtable
cd /mnt/var ; ufsdump 0uf - /dev/dsk/c0t0d0s4 | ufsrestore rf -
rm restoresymtable

5) update the vfstab to be appropriate for the cloned (alternate) disk

sed < /mnt/etc/vfstab -e s/c0t0d0/c0t1d0/g > /tmp/vfstab.new


mv /tmp/vfstab.new /mnt/etc/vfstab
# you should probably verify the contents of /tmp/vfstab.new
# before moving it into place

6) unmount all new filesystems and fsck each new FS slice

cd / ; umount /mnt
fsck /dev/rdsk/c0t1d0s0
fsck /dev/rdsk/c0t1d0s3
fsck /dev/rdsk/c0t1d0s4

7) run installboot on the alternate disk to create the bootblock

installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/c0t1d0s0

Note: on Sol10x86 (or previous versions with Grub)(added by colleague (Bill))


/sbin/installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c0t1d0s0

8) reboot your box and boot from your alternate disk... enjoy

Some details on the various steps and points of consideration:

step 1) prtvtoc will print out the disk's partition table for use
in creating the slices for the alternate disk

fmthard will update the VTOC of a disk; when -s is specified,


the next option specifies the datafile to read the VTOC info
from, though in this case it is reading STDIN from prtvtoc;
it should be noted that the drive geometry should be identical
as these two commands together will overwrite slice two of the
alternate disk

step 2) newfs creates a filesystem on the specified device (ufs by


default; one could alternately use an appropriate mkfs
command here)

step 3) mounting the alternate disk so that the master disk can be
mirrored to it

step 4) ufsdump will dump the contents of the specified device out to
the file specified prior to the device being dumped (in this
case, STDIN); the options are specified in BSD styling, not
requiring a hyphen preceding; option 0 states to dump the
entire file system, u updates /etc/dumpdates with relevant
dump information, f states to dump to a specific file which
is seen above as - (STDIN)

ufsrestore will restore the contents of a filesystem; option


r performs a recursive restoration of a filesystem relative
to the current working directory, f specifies the dumpfile
to restore from though in this case is - (STDIN) from ufsdump

step 5) the vfstab on the new device needs to be updated so that the
appropriate filesystems are mounted relative to the alternate
disk (failure to do so will cause the box not to boot if one
tries to boot from this device); the sed command is simply
changing any instances of c0t0d0 (master disk) to c0t1d0
(the alternate disk) on the copy of vfstab on the new disk

step 6) fsck is run to simply check to make sure the filesystems are
sane and usable on the alternate disk
step 7) installboot will install a bootblock to the specified slice
so that one may boot the system from it; the option
"/usr/platform/`uname -i`/lib/fs/ufs/bootblk contains the
bootblock code for the master disk; this step must be
completed otherwise the system will not boot from the
alternate disk
(Addition by colleague (Bill))
Sol10 x86 (and prev): Grub is used. These two, "stages",
one to load grub, and the other to load the OS boot code,
are stored in the MBR by installgrub.

You might also like