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 ]
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
Another alternative OS-bound command to consider is the lsblk command.
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.
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
"p" to retrieve this disk’s detailed information.
Command (m for help):
We now know everything we need to know regarding our targeted disk drive. Exit the fdisk window by keying in
Command (m for help):
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
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.
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
A more detailed output can be achieved through the fdisk utility.
$ fdisk -l sdb1.img
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
$ sudo dd if=/home/dnyce/LinuxShellTips/sdb1.img of=/dev/sdb1 bs=1k conv=noerror
With the above output, we have achieved complete restoration of backup files to their original destination.
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.