Skip to main content

How to clone individual partitions from one drive to another

Posted in

This is more a reminder for me, but this is something I always have to search for.

How to clone several partitions from one drive to another without cloding the whole drive using dd.

In this example source = sdb and dest = sdd

TLDR:
# Clone partition 1 from sdb to sdd and copy the boot sector
sudo dd if=/dev/sdb1 of=/dev/sdd1 bs=4096 conv=notrunc,noerror
sudo dd if=/dev/sdb of=/dev/sdd bs=446 count=1

Long:
Step 1: Prepare the target drive
If you don't create the partitions on the target drive, dd will write to a file in /dev and fill the source drive.
* delete all partitions
* create the new partitions with the same sizes as the the source drive.

Step 2: Clone the partitions
* For each partition, run the command substituting the drive name

sudo dd if=/dev/sdb1 of=/dev/sdd1 bs=4096 conv=notrunc,noerror
sudo dd if=/dev/sdb2 of=/dev/sdd2 bs=4096 conv=notrunc,noerror
etc

Step 3: Clone the boot sector (MBR) WITHOUT the partition table
The first 512 bytes of the boot sector contain the bootstrap and the partition table

446 bytes - Bootstrap.
64 bytes - Partition table.
2 bytes - Signature.

to replace only the bootstrap section and leave our new partition table in place:

sudo dd if=/dev/sdb of=/dev/sdd bs=446 count=1

blocksize is set to the first 446 bytes and will read only one block.