[Watford] Ghosting a Linux HDD

Yvan Seth watford.lug.org.uk at malignity.net
Fri Feb 8 17:37:07 GMT 2008


<quote who="walt">
> Hi guys,
> 
> Is there a way and/or a utility which allows me to create and image of
> a linux hard disk incl.  all partitions and then write that to another
> hard disk?  Rather like ghost in Windows.  
> 
> Although ghost will clone a linux disk it gets it wrong somewhere and
> the new disk wont boot. I suspect its that ghost cant handle ext3
> correctly or grub needs to be changed in some way (or both).

Hm, ghost usually works OK with Linux discs.

I'll now outline a highly dangerous and very fragile method that I use
very regularly.  I can't stress enough that it is DANGEROUS, but I'll
foolishly try to explain it anyway!

Alain's method is more complex but is safer and doesn't rely on good
luck, sunspots, and the direction of the wind ;)


The "linux way" to do a ghost is along the lines of:

    dd if=/dev/hdb | gzip > hdb.img.gz

That's assuming you're booted into a Linux system *not* running off the
disc /dev/hdb and that no partitions on /dev/hdb are mounted, otherwise
you're asking for trouble.  Also assuming you have enough space to store
the entire gzipped disc image (which will likely be several GB.)

Then to push the image to a new disc you can do something like:

    cat hdb.img.gz | gunzip > /dev/hdc

Now I'm assuming the disc you want to dump the data too is at /dev/hdc,
but if you do have both discs available you could do it all at once
with:

    dd if=/dev/hdb of=/dev/hdc

This is nowhere near as smart as ghost and depends on a lot of things
being "just right": hdc shouldn't be smaller than hdb, when you boot to
the destination disc the disc arrangement has to be what the boot loader
you copied across expects.

DANGER DANGER! dd-ing discs like this is a good way to b0rk your system.
One small typo and you're stuffed, you want to be damn sure that the
/dev/hdXYZ nodes you're dealing with are exactly what you think they
are.  This is dealing with raw disc devices and just smashing their
bytes around!  The "dd" method is best for backing up whole disc or
partition (i.e. /dev/hdb1 for partition 1 of the disc) images that will
later be returned to the same disc/partition.

-Yvan




More information about the Watford mailing list