I want to re-use an external drive which already contains some data. So I will create a disk image on an external drive in case I need to copy that image back to the drive in the future.


Normally, I just run dd to create an file.img when the disk is small, e.g. SD card. However, the drive capacity is 512GB. So a better option is to compress the image. Here is how this can be done:

# dd if=/dev/sde bs=64k status=progress | gzip -c > /storage/images/sabrent_disk.img.gz
512077594624 bytes (512 GB, 477 GiB) copied, 12462 s, 41.1 MB/s
7814181+1 records in
7814181+1 records out
512110190592 bytes (512 GB, 477 GiB) copied, 12467.5 s, 41.1 MB/s

Note: In the above example, /dev/sde is the device I wanted to create the image from and the image will be saved to /storage/images/sabrent_disk.img.gz.

To restore the image back to the disk, the following command can be used:

# gunzip -c /storage/images/sabrent_disk.img.gz | dd of=/dev/sdX

Again, I would replace /dev/sdX with the actual device. Remember to triple-check for that device as a mistake in picking a wrong device could make you cry the whole night.


Why do I need to write this post, many people already do this right? You could be right, but this post is to remind me, as I will not remember how to do this in a few weeks from now.