Using DD to backup your drive


How to backup your hard drive (the type of format doesn’t matter) using dd.

Boot to some rescue mode by using the install media (generally “linux rescue”) otherwise enter rescue mode manually: https://cyanogenmods.org/recovery.html

Make sure not to be booted to your hard drive, nor to have any of those partitions mounted.

Now use any combination of dd, ssh or rsh, gzip or bzip2 to backup the drive (I recommend using ssh versus rsh; however, ssh is generally not available during the rescue mode, whereas rsh is available):

You can backup the whole drive (if you have enough space on your destination system) as follows (This method also grabs the MBR):

dd if=/dev/sda | rsh user@dest “gzip -9 >20030220-backup-sda.dd.gz”

A restore using this method would be as follows:

rsh user@dest “cat 20030220-backup-sda.dd.gz | gunzip” | dd of=/dev/sda

To backup individual partitions, be sure to grab the MBR because it contains the partition table, as well as any partitions you want to backup:

dd if=/dev/sda bs=512 count=1 | rsh user@dest “cat – > 20030220-backup-mbr.dd”
dd if=/dev/sda1 | rsh user@dest “gzip -9 > 20030220-backup-sda1.dd.gz”

A restore would go as follows – be sure to restore the MBR, reboot, then restore the other partitions.

rsh user@dest “cat 20030220-backup-mbr.dd” | dd of=/dev/sda
reboot to re-read partition table (come back into rescue mode)
rsh user@dest “cat 20030220-backup-sda1.dd.gz | gunzip” | dd of=/dev/sda1

Depending on which machine is the fastest and how fast your network is, you need to decide when you will do the compression. Your choices are to compress before sending over the network, but if this machine is much slower than the server you are sending to, then it may be better to send the uncompressed data over the network to the destination server and compress as the data arrives. Just keep in mind that the transfer over the network will be a little slower if sending uncompressed data rather than compressed — also the network speed affects this too — 10 Mbit vs. 100 Mbit. Use your best judgement.

Other pages to read up on are:
How to recover Linux
File Copy using SSH
Resize data using DD command

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.