Imaging only the useful content
Ah, so the trick is knowing where the content ends. Here's the reason I'm digging into this:
I often image bootable partitions for backup purposes using dd. Rather than use a commercial tool that knows what to ignore for a given filesystem type, I'm trying to find ways to do this the GNU way without wasting too much space.
One way is to use dd to pad all the empty space with zeros (ie. dd if=/dev/zero of=/mnt/target_drive/zero.pad), so that after the drive is imaged, it compresses nicely.
Another way might be to use a defragmentation tool to pack all the data to the front of the partition, then specify a size to dd that includes the last bit of meaningful content while excluding the trailing empty space. How would I know what size to specify?
Are there any filesystems that necessarily have meaningful content at the end of a partition?
The second approach is superior because compression may not be necessary, and the restore partition can be smaller.