Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
Needs more specific detail about hardware and filesystem. –  Barry May 10 '11 at 9:47
    
cloudlinux kernel: 2.6.18-338.5.1.el5.lve0.8.25PAE; filesystem: ext3 –  Ajo Augustine May 10 '11 at 9:58

2 Answers 2

up vote 3 down vote accepted

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 "+ /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.

share|improve this answer
    
excellent; thank you. –  Ajo Augustine Feb 16 '12 at 7:49
    
I think you want to add -e after echo, otherwise the \n would be taken literally. –  itsadok Aug 21 '13 at 8:53

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.

share|improve this answer
    
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? –  Ajo Augustine May 10 '11 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 '11 at 10:20
    
Thank you; Jure –  Ajo Augustine May 10 '11 at 18:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.