1

The primary hard drive sda of my cent os server has got many 'offline uncorrectable sectors' and hence I am planning to clone the drive. But cloning the entire drive is not a feasible solution, as it is a live server with 450G of data. Also the drive is responding slowly.

I need to find a solution which will help to minimize the down time. I have a plan to partition another disk same as the primary. Then clone the mbr only. rsync the data in all the partitions. Then remove the primary disk and booting from the second drive.

I am not sure if it works. Kindly let me know your suggestions. Any alternative solutions are also appreciated.

Thanks, Ajo

2
  • Needs more specific detail about hardware and filesystem.
    – user31170
    May 10, 2011 at 9:47
  • cloudlinux kernel: 2.6.18-338.5.1.el5.lve0.8.25PAE; filesystem: ext3 May 10, 2011 at 9:58

2 Answers 2

3

In detail assuming:

-/dev/sda is the live disk and /dev/sdb is the replacement (you can further minimize downtime by installing sdb in a USB enclosure/chassis and doing all formatting/syncing through that)
-sdb is at LEAST the same size as sda

BE SURE to review it and adjust. I'm doing this with no prior knowledge of how your partitions are laid out and what your mountpoints are, etc. Post syncing shuffling of files etc. WILL be necessary. Pay close attention to the rsync line, as i'm assuming / is sda1 and you want it on sdb1.

  
# copy over the mbr. This has the added benefit over sfdisk in that the
# bootloader is also cloned over  
dd if=/dev/sda of=/dev/sdb bs=512 count=1

#OPTIONAL: grow partition of sdbX, where X is the target partition number  
#parted /dev/sdb  
#(parted) print
#(parted) resize X 

# make the new filesystem(s) and mount  
for i in $(ls -1 /dev/sdb?);do mkfs.ext3 $i;done  
for i in $(ls -1 /dev/sdb? | cut -f3 -d"/");mkdir -p /mnt/$i;\
umount /dev/$i;mount /dev/$i /mnt/$i;done  

# start the sync. exclude stuff we don't need to save time/space.  
echo -e "+ /dev/console\n+ /dev/initctl\n+ /dev/null\n+ /dev/zero\n\n- /tmp/*\n- \
/proc/*\n- /dev/*\n- /sys/*\n- /tmp/*\n- /mnt/*\n- /media/*" >> /tmp/exclude.rsync.lst  
rsync -az --exclude-from=/tmp/exclude.rsync.lst /. /mnt/sdb1/.  

#INSERT POST-SYNC TWEAKINGS HERE. doublecheck file/path locations, etc.

Congrats! done. The important parts are the exclude and making sure you dd the mbr BEFORE modifying the partition table.

2
  • I think you want to add -e after echo, otherwise the \n would be taken literally.
    – itsadok
    Aug 21, 2013 at 8:53
  • i know i'm WAY late on this, but you're 100% correct! should have just used a printf statement. :| fixed! Feb 19, 2019 at 1:53
0

I think your plan is ok, you could also rsync first to transfer all the data and then do it again at the end to sync the remaining changes that happened during the first rsync. I did something similar when I was replacing an old server with new hardware and it worked.

2
  • Thank you Jure; id it necessary that the partitioning is done the same in the two drives. My current drive is 1TB. Can I use a 2TB drive for cloning. Will this have any effect, when the mbr is cloned? May 10, 2011 at 10:03
  • I don't think it really matters. It's easier if you just copy everything, for example using sfdisk -d /dev/sda | sfdisk /dev/sdb but make sure you also copy grub or install it on the new disk
    – Jure1873
    May 10, 2011 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .