How to clone a Linux partition or hard drive from the terminal

Clone a partition or hard drive in Linux

Today, much of our important data is stored on a hard drive. To avoid losses we can make backup copies, something that we can also do in the different available clouds. As for partitions or hard drives, the best tool I have tried on any operating system is Apple's Time Machine, a system that automatically copies an entire system with only a previous configuration and an external disk. An option to get clone a partition or hard drive in Linux we can find it in the terminal.

In this article we are going to deal with a cloning, that is, what we will copy will be exactly the same as on another partition or hard drive. If all we need is to save some important data we have to use other tools or even make a manual copy. We must also bear in mind that the tool we will use is the terminal, so there will be no user interface that we can manipulate with the mouse as in Clonezilla (so so).

How to clone a partition

With the command «dd» we can copy an entire disk or just one partition. The first thing we are going to do is clone a partition. In the event that we have / Dev / sdb y / Dev / sdc, we must clone / dev / sdb1 en dev / sdc1. We will do it by following these steps.

  1. With the command Fdisk we will list the partitions:
fdisk -l /dev/sdb1/ /dev/sdc1
  1. Next, we clone the partition / dev / sdb1 en dev / sdc1 with the command "dd":
dd if=/dev/sdb1 of=/dev/sdc1

The above command tells "dd" to use / dev / sbd1 as input and write it to output / Dev / sdc1. After cloning, we can check the status of both disks with the following command:

fdisk -l /dev/sdb1 /dev/sdc1

How to clone an entire hard drive

The previous method will help us to clone a partition. If what we want is clone an entire hard drive, the output disk has to be the same size or larger than the input disk. We will clone the disk / sdb en / sdc with this command:

dd if=/dev/sdb of=/dev/sdc

If we want to check the status of the disks after cloning, we will use this other command:

fdisk -l /dev/sdb /dev/sdc

How to make a backup of our MBR

The "dd" command can also be used to make a backup of our MBR (Master Boot Record), which is located in the first sector of our device, just before the first partition. To create a backup copy of our MBR, we will write the following command:

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

The above command asks "dd" to copy / Dev / sda en /backup/mbr.img with a step of 512 bytes and the count option asks you to copy a block. In other words, it prompts you to copy the first 512 bytes of / Dev / sda in the file we have provided.

Do you already know how to clone a partition or hard drive in Linux from the terminal?

Clonezilla
Related article:
What is Clonezilla? Your friend in the face of disasters

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Jonathan Castillo said

    Hello linux adictos. After cloning a partition, how to restore it=

  2.   Pedro said

    Thank you very much, it was very useful