e2freefrag produces a read-only report showing how free space is distributed on an ext2, ext3 or ext4 file system. The report includes the smallest, largest and average free extents, plus a histogram that helps you judge whether free space is mostly in useful contiguous runs. Allow about ten minutes, plus the time needed to identify the correct block device.
This guide uses the installed e2freefrag from e2fsprogs 1.47.0-2.4~exp1ubuntu4.1. Its local manual page identifies the upstream e2fsprogs version as 1.47.0. You need the e2fsprogs package and a readable ext2, ext3 or ext4 device. Reading the block bitmap normally requires elevated privileges. The command does not repair, defragment or resize anything.
First ask findmnt which device backs the file system you want to inspect:
$ findmnt -no SOURCE,FSTYPE /path/to/mount
/dev/mapper/vg_data-lv_home ext4
Replace /path/to/mount with a real mount point. The second column must be ext2, ext3 or ext4. Pass the first column to e2freefrag, not the directory path. Be especially careful with a system using LVM, RAID or device-mapper names: copying the device printed by findmnt avoids guessing.
Checkpoint: confirm that the device is the intended file system before continuing. This check is read-only, but inspecting the wrong device can waste time and produce a report that answers a different question.
Run the command as an administrator when an ordinary account cannot open the device:
$ sudo e2freefrag /dev/mapper/vg_data-lv_home
Device: /dev/mapper/vg_data-lv_home
Blocksize: 4096 bytes
Total blocks: 1504085
Free blocks: 292995 (19.5%)
Min. free extent: 4 KB
Max. free extent: 24008 KB
Avg. free extent: 252 KB
HISTOGRAM OF FREE EXTENT SIZES:
Extent Size Range : Free extents Free Blocks Percent
4K... 8K- : 704 704 0.2%
8K... 16K- : 810 1979 0.7%
16K... 32K- : 843 4467 1.5%
Your counts and ranges will differ. The command scans the file system's block bitmap, so a busy or large file system can take time. It reports the state observed during the scan; it is not a transactionally frozen snapshot. Avoid treating a single run as a precise capacity guarantee while applications are creating or deleting files.
If you see Permission denied while opening filesystem, repeat the command with sudo or have an administrator run it. Do not work around the error by changing device permissions. If the device is not an ext2, ext3 or ext4 file system, this is the wrong tool.
Total blocks is the size of the file system in blocks, while Free blocks is the currently unallocated portion. The percentage is the free-block proportion, not a fragmentation score. A file system can have plenty of free space but still have it split into many small extents.
The three extent lines describe contiguous free runs. The minimum is the smallest run found, the maximum is the largest, and the average is calculated across the free extents reported by the scan. A large maximum does not mean that all free space is available as one large run. Compare the average and the histogram with the allocation sizes that matter to your workload.
The histogram groups extents into size ranges. Free extents counts runs in a range, Free blocks counts the blocks in those runs, and Percent shows the share of free blocks represented by that row. A high percentage in the lower ranges means much of the free space is split into smaller runs. That is evidence about layout, not proof that a particular application will fail to allocate a file.
Use -c when you want an additional count for free chunks of a chosen size:
$ sudo e2freefrag -c 1024 /dev/mapper/vg_data-lv_home
The report includes the normal summary and histogram, plus fields for the chunk size, total chunks and free chunks. The installed binary labels those fields Chunksize, Total chunks and Free chunks. The argument is in kilobytes and must be a power of two. The local manual page says it must be larger than the file system block size; this installed binary's diagnostic says the value must be greater than or equal to the block size. To avoid relying on that release-specific edge case, choose a clearly larger value such as -c 1024 on a 4096-byte-block file system.
Choose the chunk size to match the question you are investigating. For example, a workload that often needs approximately 1 MiB contiguous allocations can justify checking -c 1024. This option does not reserve space, rearrange blocks or change allocation policy.
For a review or capacity ticket, save the report with the device and collection time. The redirection changes only the new report file, not the file system being examined:
$ sudo e2freefrag -c 1024 /dev/mapper/vg_data-lv_home > /tmp/e2freefrag-home.txt
$ test -s /tmp/e2freefrag-home.txt && sed -n '1,12p' /tmp/e2freefrag-home.txt
Device: /dev/mapper/vg_data-lv_home
Blocksize: 4096 bytes
Total blocks: 1504085
Free blocks: 292995 (19.5%)
Check that the device, block size and free-block count are plausible for the system you intended. If the file is not needed, remove only that report with rm -- /tmp/e2freefrag-home.txt. There is no undo for deleting the report, but deleting it does not undo or alter the scan because the scan made no storage changes.
-c accepts bytes or arbitrary sizes. Its value is a power-of-two count of kilobytes above the block size.e2freefrag diagnoses layout; it does not recommend an automatic repair.-c value was a power of two in KB and larger than the file system block size.