full hard disk copy
dd if=/dev/hdx of=/dev/hdy
dd if=/dev/hdx of=/path/to/image
dd if=/dev/hdx | gzip > /path/to/image.gz
Hdx could be hda, hdb etc. 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
Getting around file size limitations using split
When making images, it's quite easy to run up against various file size limitations. One way to work around a given file size limitation is to use the split command.
# dd if=/dev/hda1 | gzip -c | split -b 2000m - /mnt/hdc1/backup.img.gz.
- This example is using dd to take an image of the first partition on the first harddrive.
- The results are passed through to gzip for compression
- The -c option switch is used to output the result to stdout.
- The compressed image is then piped to the split tool
- The -b 2000m switch tells split how big to make the individual files. You can use k and m to tell switch kilobytes and megabytes (this option uses bytes by default).
- The - option tells split to read from stdin. Otherwise, split would interpret the /mnt/hdc1... as the file to be split.
- The /mnt/hdc1... is the prefix for the created files. Split will create files named backup.img.gz.aa, backup.img.gz.ab, etc.
To restore the multi-file backup, do the following:
# cat /mnt/hdc1/backup.img.gz.* | gzip -dc | dd of=/dev/hda1
- Cat recombines contents of the compressed and split image files to stdout, in order.
- Results are piped through gzip for decompression.
- And are then written to the first partition of the hard drive with dd.