Is safe to replace a disk with DD?

tom3000

Verified User
Joined
Apr 1, 2008
Messages
8
My disk (not RAID) have been working for two years and I am concerned about a future crash. I want to change the disk for a new one (old 120GB, new 160GB). I found a nice and simple way to do it using dd (
# dd if=/dev/sda of=/dev/sdb)

I will do the following procedure:

I will shutdown the server, unplug it from the net, install the new disk, turn it on, run the dd function, then shut it down again, change disk position (replace first disk with second), plugin it to the net, turn it on.

Am I loosing something in this process? Should it work?

Have anybody tried this before?
 
Doing a byte by byte copy you will also copy the partition table; this will make your new disk to have the same exact partition sizes as the old one, you would have to use cfdisk and resize2fs after the copy to resize partitions and file systems.

I did it, it works, it's the best way to move a system.
Also, use a live distribution to do the copy. Unmount ALL file systems before copying, or remount them read-only with "-o remount,ro" if you need to keep a service running no matter what.

There are plenty of tutorials on the web for doing this, just search. I suggest using some distribution dedicated to data investigation or recovery, like Helix or BackTrack, to do it.
 
Last edited:
One step forward

Thanks Tillo, good answer I will try. Let´s go one step further.

If I install Centos with RAID1 array in two new disks and then copy the root partition (with DD) from my old stand alone disk to the new RAID1 array should it work?

It means I am copying a partiton running Centos OS in stand alone disk with DA installed (sda2) to a Centos OS RAID1 array partition (md2) with minimum installation resources.

I know it seemes to be a shortcut to avoid backup and restore everything but if it works will be a huge time saver.
 
I don't know about CentOS, but usually mdadm is part of the initrd (the boot-helper ramdisk) and should automatically find software raid by looking at the disks on boot, and if the kernel is compiled with the correct modules (and not as modules, but built-in) it should mount the root partition as raid just fine. Precompiled kernels usually have them.
You just have to modify /boot/grub/menu.lst to have the correct root partition, after you copied the data.
It's not necessary to do a CentOS install to create a software raid, just do it from the live distribution before moving the data with mdadm.
 
Back
Top