Friday, March 1, 2013

Clone HDD

Current HDD - sda
New HDD - sdb

------------
[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 291G 245G 32G 89% /
/dev/sda1 494M 157M 312M 34% /boot
none 4.0G 0 4.0G 0% /dev/shm
/dev/sdb3 915G 245G 624G 29% /newHDD
/dev/sdb1 494M 157M 312M 34% /newHDD/boot
----------

1) Copy the primary and extended partition table from current HDD to new HDD, you can use sfdisk for this.
sfdisk -d /dev/sda > /dev/sdb
Now the sdb have the same partions as in sda; if the sdb is larger than sda then delet the '/' partion using fdisk, and recreate it with all available space in sdb.

2) Clone /boot partition from sda to sdb using the dd command as shown below.
This command work only when the source and destination boot partitions have equal sizes and have equal number of cylinders. You can check this from the output of fdisk. If the unit size are same on both disks then only you can create similar partitions on source and destination HDD using same number of cylinders.

If the units are different, then skip this step and do rsync.
Disk /dev/sda: 319.9 GB, 319988695040 bytes
255 heads, 63 sectors/track, 38903 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb: 999.9 GB, 999989182464 bytes
255 heads, 63 sectors/track, 121575 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Here the units are same, so you can use dd to clone boot

Command to clone /boot (Here sda1 is the boot of source HDD and sdb1 is the boot of sdb)
dd if=/dev/sda1 of=/dev/sdb1

-----------
dd command syntax

dd if=INPUT-FILE-NAME of=OUTPUT-FILE-NAME
----------

3) Rsync /boot; please skip this step if you have cloned the /boot partition in the step 2.
rsync -vrplogDtH /boot/ /newHDD/boot/

4) Rsync the other directories as follows.
Note : don't rsync / to /newHDD using single rsync command (like "rsync -vrplogDtH / /newHDD")it will create loop. Also try
to unmount virtfs and exclude virtfs while syncing home dir(refer: Jailshell_virtfs )
Eg: if the / of sda looks like
------
drwxr-xr-x 82 root root 36864 Oct 31 01:33 etc/
drwx--x--x 251 root root 12288 Oct 27 20:51 home/
drwxrwxr-x 2 root root 4096 Nov 11 2009 ioncube/
drwxr-xr-x 9 root root 4096 Oct 12 07:21 lib/
drwx------ 26 root root 4096 Oct 30 04:49 root/
drwxr-xr-x 2 root root 12288 Oct 13 04:02 sbin/
drwxr-xr-x 4 root root 20480 Oct 13 04:49 sbin/
drwxr-xr-x 2 root root 4096 Jan 11 2011 selinux/
drwxr-xr-x 2 root root 4096 Jan 26 2010 srv/
drwxr-xr-x 12 root root 0 Oct 27 21:02 newHDD/
drwxr-xr-x 12 root root 0 Oct 27 21:02 sys/
drwxrwxrwt 15 root root 286720 Oct 31 01:38 tmp/
drwxr-xr-x 18 root root 4096 Jan 12 2011 usr/
drwxr-xr-x 26 root root 4096 Oct 27 21:03 var/
---------
then rsync the files and folders as follows.
---------
rsync -vrplogDtH /etc/ /newHDD/etc/
rsync -vrplogDtH --exclude 'virtfs' /home/ /newHDD/home/
rsync -vrplogDtH /ioncube/ /ioncube/ /newHDD/ioncube/
rsync -vrplogDtH /lib/ /newHDD/lib/
rsync -vrplogDtH /root/ /newHDD/root/
rsync -vrplogDtH /sbin/ /newHDD/sbin/
rsync -vrplogDtH /sbin/ /newHDD/sbin/
rsync -vrplogDtH /selinux/ /newHDD/selinux/
rsync -vrplogDtH /srv/ /newHDD/srv/
rsync -vrplogDtH /sys/ /newHDD/sys/
rsync -vrplogDtH /tmp/ /newHDD/tmp/
rsync -vrplogDtH /usr/ /newHDD/usr/
rsync -vrplogDtH /var/ /newHDD/var/
---------
OR
rsync -avpz --exclude=/home/virtfs --exclude=/new --exclude=/boot --exclude=/backup / /newHDD
5) Follow the steps in HDD_switch_-_In_the_Event_of_an_HDD_Upgrade to switch the HDD, do it only afetr getting confirmation from the client.

No comments:

Post a Comment