Advanced disk cloning
The classic disk cloning tool in linux is the dd command. This command creates a image of disk or extracts the contents from the image to disk. The dd tool needs to be handled carefully and you need to understand its use. We'll show a more advanced technique of creating a disc image that contains unallocated space. A classic example is when I have a Raspbian operating system installed on a 250 GB disc, but there's only a tiny boot partition (e.g. sda1) and my own operating system partition (sda2) which together have 15 GB. Instead of saving a 250 GB image, I would like to save only two partitions with 15 GB, so that the image is smaller and can be expanded to 16 or 32 GB flash.
Start the terminal, plug in the disk, and view the partition information with command in terminal:
sudo fdisk -u -l
In the example above, we see two partitions, one 41.8MB (boot) and then a OS partition (14.7GB). Check the last number in the Sectors column. It tells us what sector the second section ends up. Our image we'll finish behind it, so 30834688+1
Now the dd command. The basic formula looks like this:
sudo dd if = /dev/sdx of = ~/image.img
where if represents the input file (in the case of backup I take the disc e.g. /dev/sdd) and I want to create of the image.img output file. When extracting an image to the target drive, we swap it. We'll add count=, which trims the source disk to existing partitions only by specified positions. In practice, for the above disc, we will use the following command:
sudo dd bs=512 count=30834689 if=/dev/sdd of=~/pihome_20200615.img status=progress
Tip: Do you know how to learn the total size of your disk? By calculating 512 bytes * 30932992 = 15 837 691 904 bytes, or 17.1 GB. See upper screenshot.
Add comment