Home Linux Backup Tools How to Clone and Restore Linux Partition Using dd Command

How to Clone and Restore Linux Partition Using dd Command

The legacy and standards that drive the Linux operating system make it impeccable and unique among other operating system distributions in terms of achieving certain user-critical functionalities.

Most of these functionalities like backing up, restoring, and wiping out system files and user data might require the download, installation, and configuration, of certain application packages.

[ You might also like: How to Use Timeshift to Backup and Restore Linux ]

On the other hand, achieving these same user and system objectives only requires the mastery of certain OS-bound commands. The advantage of referencing such commands is that they often apply to all Linux distributions so that you do not have to worry about finding a package or command configuration that is compatible with your current Linux distribution.

[ You might also like: How to Backup Linux Filesystem Using dump Command ]

dd Command

The dd command helps Linux users to clone, backup, and restore system hard disks and their associated data. This command also extends to other user and system-critical functionalities but this article seeks to explore its applicability in creating and restoring system hard disk images.

How to List Linux Storage Device Info

We need the lsscsi utility installed to flexibly help us list all viable storage devices on our Linux system. We could resort to other internal commands like:

$ sudo fdisk -l 
List Linux Storage Devices
List Linux Storage Devices

Another alternative OS-bound command to consider is the lsblk command.

$ lsblk
List Linux Block Devices
List Linux Block Devices

How to Install LSSCSI Tool in Linux

Now let us install the lsscsi utility and note the difference in using it instead of fdisk and lsblk to list the storage devices attached to our Linux system.

$ sudo apt-get install lsscsi   [On Debian/Ubuntu & Mint] 
$ sudo dnf install lsscsi       [On CentOS/RHEL/Fedora and Rocky Linux/AlmaLinux]
$ pacman -S lsscsi              [On Arch Linux]
$ emerge sys-apps/lsscsi        [On Gentoo]
$ sudo dnf install lsscsi       [On Fedora]
$ sudo zypper install lsscsi    [On openSUSE]

Now try using this lsscsi utility to list active storage devices on your Linux system.

$ lsscsi
List Active Linux Storage Devices
List Active Linux Storage Devices

As you can see, this utility produces a more organized output compared to the latter system-bound device-listing utilities.

How to Check Linux Disk Information

From the above lsscsi output, the disk drive we will be cloning is “/dev/sdb”. The OS-bound fdisk command should give us more detailed information regarding this flash disk drive. You will need Sudo privileges to execute this command.

$ sudo fdisk /dev/sdb 
Check Linux Disk Information
Check Linux Disk Information

Key in "p" to retrieve this disk’s detailed information.

Command (m for help): p
Print Linux Disk Partition Table
Print Linux Disk Partition Table

We now know everything we need to know regarding our targeted disk drive. Exit the fdisk window by keying in "q".

Command (m for help): q

How to Clone/Backup Partition in Linux

It is from this point that we will witness the power of the OS-bound dd command. The above-listed and detailed “/dev/sdb” flash disk has one partition (/dev/sdb1).

We are going to image or clone this single partition (sdb1) using the following dd imaging/cloning command:

$ sudo dd if=/dev/sdb1 of=/home/dnyce/LinuxShellTips/sdb1.img bs=1k conv=noerror
  • if – points to the targeted device for cloning.
  • of – points to the destination storage location and assigned file name for the created device clone/image.
  • bs – depicts the needed block size configuration.
  • conv=noerror – ensures that the original data for cloning is preserved.
Linux Partition Cloning
Linux Partition Cloning

We can confirm the creation of our image/clone (sdb1.img) by navigating to its “of” location as per the dd command specifications.

$ cd /home/dnyce/LinuxShellTips && ls       
Check Linux Partition Cloning Image
Check Linux Partition Cloning Image

A more detailed output can be achieved through the fdisk utility.

$ fdisk -l sdb1.img 
Check Clone Partition Info
Check Clone Partition Info

How to Restore Clone Image in Linux

We will also make use of the dd command, as we used earlier to imaging/cloning but this time swipes the input path (if) and the output path (of) entries.

$ sudo dd if=/home/dnyce/LinuxShellTips/sdb1.img of=/dev/sdb1 bs=1k conv=noerror
Restore Clone Partition in Linux
Restore Clone Partition in Linux

With the above output, we have achieved complete restoration of backup files to their original destination.

Final Note

You should now embrace this image creation and cloning skill set to make sure you never lose any data on your machine. The dd command is very effective and easy to master. With a one-line command, you have an image backup of your data and with another one-line command, you have successfully retrieved that same data.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.