Skip to content

Instantly share code, notes, and snippets.

@kyle0r
Created August 26, 2025 11:47
Show Gist options
  • Save kyle0r/feb86878132e260017218671a44f9e30 to your computer and use it in GitHub Desktop.
Save kyle0r/feb86878132e260017218671a44f9e30 to your computer and use it in GitHub Desktop.

This snippet dumps ext2/3/4 filesystem block allocation info in MiB's

Use case: you want block level allocation info without mounting the filesystem

Example output:

used: 8599.37 MiB
free: 13926.63 MiB
total: 22526.00 MiB
ext_part=/dev/zd64p1

dumpe2fs -h "$ext_part" | awk '
/Block count:/ {blocks=$3}
/Free blocks:/ {free=$3}
/Block size:/ {bsize=$3}
END {
  used_blocks = blocks - free
  used_mib = used_blocks * bsize / (1024*1024)
  free_mib = free * bsize / (1024*1024)
  total_mib = blocks * bsize / (1024*1024)
  printf("used: %.2f MiB\nfree: %.2f MiB\ntotal: %.2f MiB\n", used_mib, free_mib, total_mib)
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment