The dd is a command which stands for “data duplicator”. This command is used for copying and converting data. The dd command simply copies standard input to standard output, read in 512-byte blocks. You can use the dd command to back up the entire hard disk or partition. Using the dd command you can also backup the MBR.
Go through this tutorial and understand the uses of dd command.
#1 – Create Backup of Existing Partition
The following command will create a backup of the entire partition /dev/sdb1 and write to /backup/sdb1.img file.
dd if=/dev/sdb1 of=/backup/sdb1.img
Sample Output
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
Now restore the data to another empty partition /dev/sdb2. Execute the below command to do the restoration.
dd if=/backup/sdb1.img of=/dev/sdb2
Sample Output
16064937+0 records in 16064937+0 records out 8225247744 bytes (8.2 GB) copied, 197.688 s, 41.6 MB/s
You can see the content on the new disk /dev/sdb2. This will look like a replica of /dev/sdb1.
#3 – Create Duplicate Partition with Existing
You can directly create a duplicate partition using the existing partition. Use the following command to replicate the partition /dev/sdb1 to /dev/sdb2 without creating any backup file.
dd if=/dev/sdb1 of=/dev/sdb2
Sample Output
16064937+0 records in 16064937+0 records out 8225247744 bytes (8.2 GB) copied, 221.431 s, 37.1 MB/s
#4 – Clone the Existing Hard Drive
In the above steps, you learned how to copy the entire partition. Now I have to copy the entire hard drive /dev/sda with two partitions to another hard drive /dev/sdb. First, use the below command to copy the first 446 bytes. Which will copy the MBR from the first disk to the second. This will create the second disk bootable as well.
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 one by one to new hard drive:
dd if=/dev/sda1 of=/dev/sdb1 dd if=/dev/sda2 of=/dev/sdb2
#5 – Backup and Restore MBR to Image File
Let’s create the backup of MBR to an image file. Execute below command to backup MBR of /dev/sda drive to the /backup/backup-mbr-sda.img file.
dd if=/dev/sda of=/backup/backup-mbr-sda.img bs=512 count=1
Sample output
1+0 records in 1+0 records out 512 bytes (512 B) copied, 0.0115243 s, 44.4 kB/s
The next step is to restore MBR to another disk. Use the following command to do it.
dd if=/backup/backup-mbr-sda.img of=/dev/sdb bs=446 count=1
2 Comments
Thanks for this.
However, it doesn’t address perhaps the most pragmatic of partition operations :
– to clone the OS partition and boot from it.
DD does not permit copying a partition onto free space, and there are limitations on what partition it will copy a partition onto.
I am yet to find instructions showing DD can place a clone at a specific location on free space.
seek=N skip N obs-sized blocks at start of output will put your output anywhere you want, based on block size of the target. what do you mean by free space? are you referring to an unallocated, empty drive, with no partitions? if so, then dd will copy to that. dd is a tool that just does raw, sector by sector reads and writes, and if the data on the source is properly created, the output should be as well. so you should be able to use dd to copy a disk to a larger disk, and offset the placement with the seek command, as long as you now the number of blocks to skip.