Full hard drive or partition cloning is not normally used for data backup, but instead is used for creating an exact copy of a system elsewhere, or as a non-destructive method to perform hard drive forensics, whereby a disk or partition is cloned and the rest of the operations will just be performed on the cloned image.
There are many ways to achieve this in
Linux such as by using tools such as
dd is the the simplest and is installed by default in most
dd could be used to copy a disk or partition on a block level directly to another disk or partition, or to a file.
Clone hard drive and partition using dd:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 88.5M 1 loop /snap/core/7270 loop1 7:1 0 54.1M 1 loop /snap/lxd/10972 loop2 7:2 0 89.4M 1 loop /snap/core/6818 loop3 7:3 0 54.1M 1 loop /snap/lxd/11098 loop4 7:4 0 89.3M 1 loop /snap/core/6673 sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1M 0 part └─sda2 8:2 0 20G 0 part / sdb 8:16 0 5G 0 disk └─sdb1 8:17 0 5G 0 part /mnt/data sr0 11:0 1 748M 0 rom
For this example, we're going to clone the
sdb1 partition to an image file.
From the above
sdb1 is a 5GB partition mounted on
$ sudo umount --force /dev/sdb1
$ df -h /dev/sda2 Filesystem Size Used Avail Use% Mounted on /dev/sda2 20G 5.2G 14G 28% /
Target disk drive or partition need to have at least the same capacity, and mounted partition for the target file need to have at enough free disk space. In this case, our target mounted partition still have 14GB available for the required 5GB.
$ sudo dd if=/dev/sdb1 of=/root/sdb1-backup.img conv=noerror,sync status=progress [sudo] password for user: 5347731456 bytes (5.3 GB, 5.0 GiB) copied, 49 s, 109 MB/s 10483712+0 records in 10483712+0 records out 5367660544 bytes (5.4 GB, 5.0 GiB) copied, 49.2271 s, 109 MB/s
Cloning an entire disk will also clone the master boot record and partition table
$ sudo file /root/sdb1-backup.img /root/sdb1-backup.img: Linux rev 1.0 ext4 filesystem data, UUID=d430e0a1-ec3e-4bed-b16a-e2d35d0f4ed6 (extents) (64bit) (large files) (huge files)
Share your thoughts, suggest corrections or just say Hi. Login not required.