I'm shrinking a Linux SDCard partition using AOakley's awesome guide. I'm trying to automate it, but there appears to be no command-line tool for determining the number of bytes in a partition that are used.
For example, gparted tells me the used space is 1.88GB out of 6.99GB (note, I'm using /dev/loop0 which is mounted to the second partition of /dev/sdb):
df is wrong:
% df /dev/loop0 Filesystem ... Use% udev ... 0%
parted don't print used space.
What can I use from the command-line to determine the used space in a partition the way
ANSWER: Summary from below: The partition is
ext4 which allows me to use
dumpe2fs and extract:
block count (total), and
block size which can be combined to exactly match
gparted. Turns out that
resize2fs handles fragmentation during the shrink. See the manpage for
ext4 for more info (although the manpage editor is a tad bitter about GiB vs. GB! :)