Simple Hard drive backup on the command-line (ghost-like)

  toucheatout  2006-08-09 09:26  Linux  

The tool: dd

Simplest tool from linux toolbox: just reads and writes from stdin to stdout. However, input and output can be specified, including from a raw device. We have then the equivalent of ghost, that is sometimes called a master - that is, a default install that is going to be forced into a computer, for crash recovery but also to automate desktop installs: makes everything the same thus really easier to maintain. Bang your head a tenfold more for one install and avoid banging it again.

Doing ghost-like backup (or master)

Second line includes compression to reduce size - works really well with non-full hard drives:

dd if=/dev/hdX of=/where/to/put/my_image
or
dd if=/dev/hdX | gzip > /where/to/put/my_image.gz

Restore the backup


dd if=/where/to/get/my_image of=/dev/hdX
or
gzip -dc /where/to/get/my_image | dd of=/dev/hdX

If you want to mirror a hard drive on another one:

dd if=/dev/hdX of=/dev/hdZ

Doing just the MBR

The first 512 bytes of a hard drive contains the MBR and the partition table. It is usually a good idea to backup it. The MBR is where the computer first branches in when booting a hard drive (eg LILO or grub have at least part of their code there). The partition table comes after 446 bytes - which is why you only have a maximum of 4 primary partitions on a standard PC.

Backuping the MBR and partition table:

dd if=/dev/hdX of=/where/to/put/my_MBR_image count=1 bs=512

Restoring a MBR + partition table:

dd if=/where/to/get/my_MBR_image of=/dev/hdX

add count=1 bs=512 if you're a bit paranoid/distracted/etc...
Restoring a MBR without the partition table:
It may come handy if the backup you are doing only concern a first (system) partition. The user-defined partitions will not be overwritten (if it is the case, i'll suggest that you grab trinux bootable cd (By cgsecurity - Christophe Grenier).

dd if=/where/to/get/my_MBR_image of=/dev/hdX count=1 bs=446

 
Informatics


yro.slashdot.org - Your Rights online


nytimes.com New York Times - International


Informatic headlines