Dealing with disk images with dd


by David Lutton, 2020/03/11

Using dd and gzip to create and restore disk images

First order of business with dd is to work out which device you are targeting lsblk -a | grep -v loop shows disks and partitions

If you need to check what the partitions are sudo fdisk -l /dev/YOURDEVICE

To copy the disk sudo dd status=progress bs=4M if=/dev/YOURDEVICE | gzip -c7 YOURIMAGENAME.img.gz

To generate a checksum from the disk sudo sha1sum /dev/YOURDEVICE

To generate a checksum from the image zcat YOURIMAGENAME.img.gz | sha1sum -

To write out the disk image zcat YOURIMAGENAME.img.gz | sudo dd status=progress bs=4M of=/dev/YOURDEVICE

List disks

lsblk -io kname,size disks and partitions
lsblk -ido name,size just disks/loops

dd skipping disk errors

Add conv=noerror to the command for disks that are producing read errors

What I'm using this for

I'm cloning test instruments disks, these are sparsely used disks
Around 6GB used on a 80GB disk, gzips to around 5GB

Why dd & gzip

dd and gzip are standard in `nix OSes so a live Linux distro can be used for this task