Linux Commands and Scripts

How To Clone a Partition in Linux

In this article, we will clone a partition in Linux. We will cover cloning a partition as well as hard drive.

Cloning entire partition to partition is easy with dd command. For this demonstration purpose, we are using /dev/sda1 to clone into /dev/sdb1.

List the partition using fdisk command

# fdisk -l /dev/sda1/ /dev/sdb1

Now, clone the partition using following command

# dd if=/dev/sda1  of=/dev/sdb1

The above command tells dd to use /dev/sda1 as input file and write it to output file /dev/sdb1.

After the cloning, verify it using fdisk command:

# fdisk -l /dev/sda1 /dev/sdb1

How to Clone Linux Hard Drive?

Cloning hard drive is similar to partition. We need to change name of the device. It is recommended that the hard drive is same in size (or bigger) than the source drive.

# dd if=/dev/sda of=/dev/sdb

This should have copied the drive /dev/sda with its partitions on the target hard drive /dev/sdb. We can verify the changes by listing both drives with fdisk command.

# fdisk -l /dev/sda /dev/sdb

How to Backup MBR in Linux?

dd command can also be used to backup your MBR, which is located at the first sector of the device, before the first partition. So if you want to create backup of your MBR, use following command:

# dd if=/dev/sda of=/backup/mbr.img bs=512 count=1.

The above command tells dd to copy /dev/sda to /backup/mbr.img with step of 512 bytes and the count option tells to copy only 1 block. In other words you tell dd to copy the first 512 bytes from /dev/sda to the file you have provided.

We have seen how to clone a partition in Linux.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles