In Linux, cloning a disk (USB/SSD/HDD) is really simple, using dd
utility we can make identical copies of one disk to another disk. Basically, the command will be:
sudo dd if=/dev/sdX of=/dev/sdY bs=4M status=progress
sudo fdisk -l
and read the result.If we have a large disk as source (sdX) and a smaller disk as destination (sdY), in order to ensure that the clone operation will succeed and that all used data from source disk will be copied to the destination, including the boot sector, we need to check first that partitions from sdX (and used space inside) will fit into the sdY destination disk.
Case study: if we have a 32GB(sdb) USB/SSD/HDD with two partitions, one of 1GB(sdb1) and one of 31GB (sdb2) and we need to clone this disk into a 8GB one (sdc) then this operation is possible if
a) 8 GB (available space in sdc) - 1 GB (sdb first partition [sdb1]) - 31 GB (sdb second partition [sdb2]) >= 0
and b) unused space from sdb remain "unallocated" and positioned/moved to the end of the disk
In this example, assuming that used data from sdb2 (the 31GB partition from the source disk) is not larger that 7GB all we need is to shrink this partition to <= 7GB and let the remaining space unallocated.
Gparted: disk space on a large disk that need to be cloned into a smaller disk |
|
To do the math, resize/move partition(s), we will use Gparted and if we manage to resize the partitions accordingly then we are ready to go
sudo dd if=/dev/sdX of=/dev/sdY bs=4M status=progress
That’s it, when dd
will finish you will have the destination disk bootable and with all the data intact.