How to Clone a Partition or Hard drive in Linux

There are many reasons why you may want to clone a Linux partition or even hard drive, most of which are related to creating backups of your data. There are multiple ways you can achieve this in Linux by using some external tools such as partimage or Clonezilla.

However in this tutorial we are going to review Linux disk cloning with tool called dd, which is most commonly used to convert or copy files and it comes pre-installed in most Linux distributions.

How to Clone Linux Partition

With dd command you can copy entire hard drive or just a Linux partition. Lets start with cloning one of our partitions. In my case I have the following drives: /dev/sdb, /dev/sdc.. I will clone /dev/sdb1/ to /dev/sdc1.

Read Also: How to Clone Linux Partitions Using ‘cat’ Command

First list the these partitions using the fdisk command as shown.

# fdisk -l /dev/sdb1/ /dev/sdc1
List Linux Partitions
List Linux Partitions

Now clone a partition /dev/sdb1/ to /dev/sdc1 using the following dd command.

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

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

Clone Linux Partition with dd Command
Clone Linux Partition with dd Command

After cloning Linux partition, you can then check both partitions with:

# fdisk -l /dev/sdb1 /dev/sdc1
Verify Linux Partition Cloning
Verify Linux Partition Cloning

How to Clone Linux Hard Drive

Cloning a Linux hard drive is similar to cloning a partition. However, instead of specifying the partition, you just use the entire drive. Note that in this case it is recommended that the hard drive is same in size (or bigger) than the source drive.

# dd if=/dev/sdb of=/dev/sdc
Clone Hard Drive in Linux
Clone Hard Drive in Linux

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

# fdisk -l /dev/sdb /dev/sdc
Verify Linux Hard Drive Cloning
Verify Linux Hard Drive Cloning

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, simply run:

# 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.

Backup MBR in Linux
Backup MBR in Linux

That’s all! dd command is a powerful Linux tool that should be used with caution when copying or cloning Linux partitions or drives.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Marin Todorov
I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

7 Comments

Leave a Reply
  1. Two interesting option :

    1. status=progress – this gives progress status during the copy.
    2. bs= 16K – fix the block size to 16 Kilobytes, this increases the speed (you can select other values but the default one is too small and reduces the bandwidth).

    Regards

    Reply
  2. Well, after working for an hour or so – without error message – it bricked my system completely. Also the so much favored “Boot Repair Disk” made the catastrophe even worse. The problem seems the discrepancy of the sector size in both partitions.

    Only my Windows System boots ok – but with mysterious error messages.

    So this is not the solution to my problem. I can start from scratch now and install a new system.

    Reply
  3. Are you referring dd related to OS disk ? dd is mostly used to copy data (disk dump) from one disk to another as cp is not copying entire data completely.

    In case of physical servers mostly H/W raids are configured as RAID 1 for OS. For data volumes if required you can create mirrored volume in LVM or if you are using Veritas you can create desired RAID.

    Rsync will be good option as it is also used as data replication across site as well as locally .

    Cheers

    Reply
  4. The big problem with dd is that if an error is found, when it is cloning, it stops. But this can be avoided adding: conv=sync,noerror
    Greetings.

    Reply
    • @Romualdo,

      Yes, I do agree with you, even i have faced many times with dd command. Thanks for sharing the tip, never heard about this options..

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.