duplicate a Linux system disk

Gus Wirth gwirth79 at gmail.com
Sun Aug 5 12:05:39 PDT 2007


Michael J McCafferty wrote:
> All,
> 	I have a customer who has a lot of time invested in configuring his
> system and is ready to put it in to production. However, we are getting
> some disk errors on occasion and it's tough to trust it for the long
> haul. What is the hot ticket for putting the exact same thing on another
> drive. It's easy to have another identical server sitting next to it at
> the same time, or put an identical disk in the same system to copy stuff
> over.
> 
> 	I am sure I could spend the time to do dd and fdisk, etc, but dumb it
> down and speed it up for me. :o)  Hmm... can I put a second disk in the
> system and do a dd if=/dev/hda of=/dev/hdb and will that get the boot
> sectors, etc ? Is it that simple ?

Yes, it is that simple. That's how I back up my home system. Although I 
would put the second/backup drive on a different controller for 
simplicity and performance  reasons. Here's how I do it:

Main disk is attached as primary master /dev/hda in a removable drive 
rack (Lian Li RH-40 if you want to know)

Backup disk is in a removable drive rack (same as primary) on secondary 
master /dev/hdc [1]. The backup disk preferably should be identical to 
the main disk but can be bigger. Logical Block Addressing (LBA) got rid 
of all the CHS weirdness a long time ago.

Since both drives are jumpered as master it's trivial to swap drives 
because they are both in the same rack type and configuration. As an 
alternative you could put the backup drive in an external USB or 
Firewire box. Modify the below instructions accordingly.

Boot the system with your favorite rescue CD that will recognize the 
drives and their controllers and also has the dd command. Mine happens 
to be Knoppix.

Either become root or use sudo the following:

$ sudo dd if=/dev/hda of=/dev/hdc bs=1M

WARNING: If you are using Knoppix, make SURE you turn off swap! 
Otherwise it will use the swap on the backup disk, and you will 
overwrite swap that is in use. It WILL crash your session! You also want 
to make sure you turn on DMA because it will seem to take forever for a 
large sized disk without it.

I set the block size to 1 megabyte to ensure the buffers get used. That 
number works well for me.

This will create an exact duplicate of the entire drive when it is 
finished. It takes me about 40 minutes to duplicate a 60GB disk.

Store the backup drive somewhere safe.

If you have data that is changing and you want to synchronize the 
backups, you may be able to use rsync on just the data portion, say 
/home, without having to go through the whole dd cycle. Just plug in the 
disk (if it isn't already connected), mount the appropriate partition, 
and run rsync for that partition/directory.

You left off a lot of required info for a better answer, like how often 
you want backups to happen, whether you can be offline for a period of 
time, who will be making the backups, etc. but hopefully this will give 
you an idea.

Gus

[1] Not really, but this illustrates the point.



More information about the KPLUG-List mailing list