I've an image of a bootable 16GB SD card. I've created the image with:
cat /dev/sdd | gzip >sdcard.img.gz
And I was happy because
$ du -h sdcard.img.gz 482M sdcard.img.gz
482MB instead of 16GB, yay!
Here're the details of the (uncompressed) image:
$ du -h sdcard.img 15G sdcard.img $ partx -s sdcard.img NR START END SECTORS SIZE NAME UUID 1 16384 81919 65536 32M 6e1be81b-01 2 81920 3588095 3506176 1.7G 6e1be81b-02
However, now I need to write this image back to the SD card but I don't want to write 14GB of trailing zeros/junk! That'd take ages.
- How can I create image without copying what's after the last partition?
- When I already created image of whole SD card, how can I truncate it to not include useless junk?
The point is, I don't care about the size the image is taking in the backup, but I care about the size that's transferred back to SD card, because copying to SD card is slow and copying 14GB of useless data is pointless. So compressing the disk image or copying to a sparse aware filesystem as other answers on Internet suggest is not what I'm looking for.