Affiliate Disclosure: By buying the products we recommend, you help keep the lights on at MakeUseOf. Read more.
Just because you’re running a Linux operating system doesn’t mean that you won’t run into problems from time to time. It’s always good to have a backup plan, just in case a problem strikes. Perhaps a rare Linux virus will attack; perhaps you’ll be targeted by ransomware scammers. Maybe the hard disk drive (HDD) will fail.
By cloning your Linux hard disk drive, you create a disk image that can be restored later. But how do you clone your Linux hard drive?
Linux Disk Cloning Tools
Your Linux installation might develop a bug; you could be upgrading your hard disk drive to a larger volume. Whatever the problem, if you have a backup of your disk, getting things back up and running again will be relatively simple.
Linux has four disk cloning solutions you should consider:
Whether you use functions that are built into your Linux operating system, or you install a third-party tool, it shouldn’t be long before you’re able to get your system back up and running.
Let’s look at each the four main options for cloning a drive in Linux.
1. dd: The Native Linux Disk Cloning Tool
Perhaps the most powerful Linux tool of them all, dd (sometimes referred to as “disk destroyer”) can clone an entire HDD or disk partition to another. But if misused, it can delete the contents of your disk.
As such, you should use with extreme care. You’ll find dd built into most Linux operating systems. If not, install it from the package manager. To clone your computer’s hard disk, use the command:
dd if=/dev/sdX of=/dev/sdY bs=64K conv=noerror,sync
Here, sdX is the source disk, while sdY is the destination. The numerical value 64K, corresponds to the block size command, bs. The default value is 512 bytes, which is very small, so it’s best to include 64K or the larger 128K as a condition. However: while a larger block size makes transfer quicker, a smaller block size makes the transfer more reliable.
If you only want to clone a partition of your drive, use
dd if=/dev/sda1 of=/dev/sdb1 bs=64K conv=noerror,sync
As you can see, the partition sda1 (that is, partition 1 on device sda) will be cloned to sdb1 (a newly created partition 1 on device sdb), for instance a secondary, or external, HDD attached to your computer.
Tap Enter to run the command. How long it takes will depend on the size of the disk or partition. Just make sure that destination volume is large enough to store it!
2. Linux Partition Cloning Tool, Partimage
If you have run into problems trying to get your head around the instructions with dd, or would prefer to avoid accidentally deleting your HDD with typo, partimage is also available for most distros, and doesn’t carry any “disk destroyer” risks!
However, partimage does not support the ext4 filesystem, so avoid using it for cloning disks or partitions of that type. However, if necessary, it can be used to clone Windows disk formats (FAT32 or NTFS, although this is experimental) as well as the more widely used Linux filesystem ext3, and other, older alternatives.
Before starting, ensure that the partition you wish to clone is unmounted (with the umount command). Otherwise you’ll need to exit partimage to do so before continuing with the process. You can exit at any time with the F6 key.
For Ubuntu, install with:
sudo apt install partimage
Launch from the command line with:
This is a mouse-driven application, which requires you to first select the partition to be cloned.
Tap right on the arrow keys to move to the next section, then Image file to create/use and give it a name (or enter the filename of the image to be restored).
Select the correct Action to be done (ensure the chosen option has an asterisk) and press F5 to proceed. In the following screen, select the Compression Level, and your preferred Options. You also have the choice of setting an image split mode and setting an instruction for what should happen after the backup is made.
Tap F5 to continue, confirm the details, then tap OK to begin the process. The speed of this will depend on the power of your computer.
If you’re looking for a quick and dirty—but safe—disk cloning solution for Linux, use partimage.
3. Partclone: Software for Partition Imaging and Cloning
For a more mature alternative to dd that supports backups of the ext4 filesystem, partclone is simple to use, but again requires text commands rather than a keyboard or mouse driven interface. Install with:
sudo apt install partclone
And launch with:
…where [fstype] is the filesystem type of the partition you wish to clone.
The following command will create a disk image of hda1 (hard disk drive 1, partition 1) called hda1.img:
partclone.ext3 -c -d -s /dev/hda1 -o hda1.img
You might want to restore that image, so use
partclone.extfs -r -d -s hda1.img -o /dev/hda1
Further details on usage can be found on the partclone website.
4. Clone Your Linux Drive With Clonezilla
For a more flexible solution, why not try Clonezilla? This popular disaster recovery solution is based on Partclone and designed for a range of disk cloning tasks. All the expected filesystems are supported, across Linux, Windows, and macOS (and beyond).
Unlike dd and Partclone, Clonezilla is available as a bootable ISO. You can write this to DVD or USB stick to fully clone your Linux HDD. Clonezilla is straightforward to use, with keyboard-driven menus rather than obscure commands, so anyone can get to grips with it.
While Clonezilla can be setup as a standalone utility, you might prefer to use it as part of Hiren’s Boot CD recovery tool.
You can also use Clonezilla in a professional capacity, to image multiple similar PC setups with the same operating system.
Cloning Your Linux Hard Drive Is Easy
If you’ve never cloned a hard disk drive before, you may be feeling a little reluctant to get started. It can be intimidating, especially if you’re in dire straits with a damaged HDD that desperately needs cloning before failure.
While you might prefer to simply sync your vital data to the cloud, it is always a good idea to have a full disk backup that you can quickly restore in the event of system errors. Remember to use these tools with care, however, as they can easily cause you to accidentally lose your data.
Backing up your data is vital! Learn how to optimize your backups on Linux.