brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: e2freefrag shows how chopped up the free space on an ext4 disk is

Disk
~/tips/tip-filesystems-e2freefrag-free-space

sudo e2freefrag /dev/sdb1

Reports free space fragmentation on ext2, ext3 and ext4, with a histogram of free chunk sizes.

Free space is not always one nice block. After years of creating and deleting files, a disk can have plenty of room that is split into tiny pieces. e2freefrag measures that, and it ships with the ext4 tools you already have.

sudo e2freefrag /dev/sdb1

It scans the block bitmaps and reports how many free blocks sit together, with the smallest, largest and average free extent plus a histogram of all free chunks. The man page says you can use it to gauge the level of free space fragmentation.

On a small test image filled with 1500 files of 16 KB, after deleting every second file, it reported this:

Free blocks: 9631 (58.8%)

Min. free extent: 16 KB
Max. free extent: 26524 KB
Avg. free extent: 48 KB
Num. free extent: 749

The average of 48 KB next to one big 26 MB chunk tells the story: lots of holes, one large area. The histogram below it shows where the free blocks sit, in this case mostly in the 16 KB to 32 KB range and in one 16 MB to 32 MB range.

With -c you ask about one chunk size:

sudo e2freefrag -c 64 /dev/sdb1

It adds a line with the number and percentage of free chunks of that size. The chunk size is in KB, must be a power of two and must be larger than the filesystem block size.

One caveat: this only looks at free space, not at your files. For that, e4defrag -c gives a score. The e4defrag man page also warns that fragmented free space can stop it from improving a file, so the two tools work well together.

Further reading: e2freefrag(8) man page

More Disk tips sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h ls -l /dev/disk/by-id/ All Disk tips (44) All topics

Link