Backup partition with dd (for linux, no ntfs neither hfs)


1. Empty the unused block of the hard disk with zeros. You can do that creating a file with this blocks, and erasing this file:

sudo dd if=/dev/zero of=/tmp/bigfilefullofzeros && rm /tmp/bigfilefullofzeros

It takes a long time. Really I’ve never do it totally. The reason to do that it that is to get a better compression at the end (I’ll explain later)

2. To make the copy:

sudo dd if=/dev/sdax conv=sync,noerror bs=64K | gzip -c > /pathofthebackup/system_drive_backup.img.gz

if=/dev/sdax is the path of the source partition. “conv=sync,noerror” is necessary for no dd no stop if find an error. bs=64k can be different but it works like that. gzip -c is to compress the backup file. I did a backup of a 19 Gb partition with only 4,7 Gb friee, in a less than 7 Gb file.

3. You can do a copy of the MBR (necessary for backup a boot filesystem)

sudo dd if=/dev/sda of=backup-of-sda-mbr count=1 bs=512

4. Restore the partition (I didn’t do that still):

su –
cat system_drive_backup.img.gz.* | gzip -dc | dd of=/dev/sdax conv=sync,noerror bs=64K

5. Restore MBR (if necessary):

dd if=backup-of-sda-mbr of=/dev/sda

6. Restore MBR (without restore the partition table). Just restore the first 446 bytes:

dd of=/dev/sda if=backup-of-hda-mbr bs=446 count=1



I have backed up my system to an external ximeta drive using “dd” and the well-known linux live cd distribution, Knoppix to boot from. Below are the steps in brief:

  1. Boot from the live cdrom distribution.
  2. Switch to root.
  3. Make sure NO partitions are mounted from the source hard drive.
  4. Mount the external HD.
      # mount -t vfat /dev/sda1 /mnt/sda1
  5. Backup the drive.
      # dd if=/dev/hda conv=sync,noerror bs=64K | gzip -c  > /mnt/sda1/hda.img.gz

    “dd” is the command to make a bit-by-bit copy of “if=/dev/hda” as the “Input File” to “of=/mnt/sda1/hda.img.gz” as the “Output File”. Everything from the partition will go into an “Output File” named “hda.img.gz”. “conv=sync,noerror” tells dd that if it can’t read a block due to a read error, then it should at least write something to its output of the correct length. Even if your hard disk exhibits no errors, remember that dd will read every single block, including any blocks which the OS avoids using because it has marked them as bad. “bs=64K” is the block size of 64×1024 Bytes. Using this large of block size speeds up the copying process. The output of dd is then piped through gzip to compress it.

  6. To restore your system:
      # gunzip -c /mnt/sda1/hda.img.gz | dd of=/dev/hda conv=sync,noerror bs=64K

    NOTE: I’ve had much success leaving out “conv=sync,noerror” during restore.

  7. Store extra information about the drive geometry necessary in order to interpret the partition table stored within the image. The most important of which is the cylinder size.
      # fdisk -l /dev/hda > /mnt/sda1/
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

1 Response to Backup partition with dd (for linux, no ntfs neither hfs)

  1. I am really pleased to glance at this web site posts which consists of tons of useful data, thanks for providing these kinds of statistics.|

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s