Saturday, February 27, 2010

Backup Using dd Command

In the linux system, there is a powerful tools named dd that can create an iso image from a CD/DVD, backup and restore your MBR or harddisk. Here's the usages :

  • Full hard disk copy
    dd if=/dev/hdX of=/path/to/image
    dd if=/dev/hdX | gzip > /path/to/image.gz

    X could be a, b, etc depends on your device node. If you have a SCSI device, the nodes are sdX. if means input file and of means output file. In the second example, gzip is used to compress the image if it is really just a backup.
  • Restore backup of hard disk copy
    dd if=/path/to/image of=/dev/hdX
    gzip -dc /path/to/image.gz | dd of=/dev/hdX

  • MBR backup
    In order to backup only the first few bytes containing the MBR and the partition table you can use dd as well.

    dd if=/dev/hdX of=/path/to/image count=1 bs=512

  • MBR restore
    dd if=/path/to/image of=/dev/hdX

    Add count=1 bs=446 to exclude the partition table from being written to disk. You can manually restore the table.

Please note that if you are using kernel or above, there are no more hdX device node. They are replaced by sdX.

0 comments to “Backup Using dd Command”

Post a Comment