Create SD card image - only partitioned space

I have a 32GB drive (SD card) with 4 partitions. Total partitioned space is <2GB.

I need to make an *.img file so that I can clone it to other SD cards which are smaller than 32GB.

If I just use “dd” I get an image file that is the full size of the card - 32GB.

This is all under Linux and the SD card is bootable, so can’t just copy files.

Any suggestions?

Thank you,


You can adapt from the blog post I wrote here. Using tar, to backup the rootfs, and other partitions. And sfdisk to create the the partitions.