DD Used Space Only Image File Using Gzip Solved
The problem is how to create an img of a disk (or storage of any kind) while not saving the entire unused space – shrink empty disk space with dd.
Like many similar problems, I found many posts about how to save the img of a disk and remove empty partitions. Most are obsolete or did not work as specified, which is quite irritating when you need a quick solution to a simple problem. So here is what I found that worked for me – perfectly! Add it to your SAF tools (Swiss Army Knife) collection.
dd bs=2048M if=/dev/mmcblk0 | gzip > /home/me/compressed.img
cat /home/me/compressed.img | gunzip | dd of=/dev/mmcblk0