dd is very simple backup tool available with almost Linux distribution. The ‘dd’ tool simply copies standard input to standard output, read in 512-byte blocks.
Using dd command we can create replica of entire disk, create backup of disk drives etc. The following article will help you with some usefull tips of ‘dd’ command.
1: Create Backup of Existing Partition
Following command will create a backup of entire partition /dev/sdb1 in /opt/sdb1.img file.
# dd if=/dev/sdb1 of=/opt/sdb1.img
16064937+0 records in 16064937+0 records out 8225247744 bytes (8.2 GB) copied, 123.319 s, 66.7 MB/s
2: Restore Backup to Other Partition
We can restore partition from backup created above to other partition ( /dev/sdb2 ) using following command.
# dd if=/opt/sdb1.img of=/dev/sdb2
16064937+0 records in 16064937+0 records out 8225247744 bytes (8.2 GB) copied, 197.688 s, 41.6 MB/s
Now you can see that /dev/sdb2 is replica of /dev/sdb1.
3: Create Duplicate Partition with Existing One
We can directly create a duplicate partition from existing partition. Following command will create replicate of /dev/sdb1 to /dev/sdb2 .
# dd if=/dev/sdb1 of=/dev/sdb2
16064937+0 records in 16064937+0 records out 8225247744 bytes (8.2 GB) copied, 221.431 s, 37.1 MB/s
4: Create Clone of Existing Hard Disk
Following command will copy first 446 bytes which is the MBR from the first disk to the second. This will create the second disk bootable. .
# dd if=/dev/sda of=/dev/sdb bs=446 count=1
1+0 records in 1+0 records out 446 bytes (446 B) copied, 0.00174812 s, 255 kB/s
Now make sure the partitions on /dev/sdb match with /dev/sda. Once this is done, you can copy each partition using:
# dd if=/dev/sda1 of=/dev/sdb1 # dd if=/dev/sda2 of=/dev/sdb2
5: Backup and Restore MBR to Image File
Create a backup of MBR to image file using following command.
# dd if=/dev/sda of=/opt/backup-mbr-sda.img bs=512 count=1
1+0 records in 1+0 records out 512 bytes (512 B) copied, 0.0115243 s, 44.4 kB/s
Next steps is to restore MBR to different disk, Use following command to do it.
# dd if=/opt/backup-mbr-sda.img of=/dev/sdb bs=446 count=1