Checking Free Space Fragmentation with e2freefrag (with examples)
- Linux
- November 5, 2023
Use Case 1: Checking contiguous and aligned free space
To check how many free blocks are present as contiguous and aligned free space on an ext2/ext3/ext4 filesystem, you can use the e2freefrag
command with the following code:
e2freefrag /dev/sdXN
Motivation: This use case is helpful when you want to analyze the fragmentation level of free space on a specific drive or partition. It allows you to understand how the free space is distributed and whether it is fragmented or not.
Explanation: The /dev/sdXN
argument represents the device or partition you want to check. /dev/sdX
denotes the drive, while N
denotes the partition number.
Example Output:
Free space on /dev/sdXN:
Total free blocks : 248051
Total aligned free blocks : 248051
In this example, the output shows that there are 248,051 free blocks available, and all of them are contiguous and aligned. This indicates that the free space is not fragmented.
Use Case 2: Specifying chunk size to print free chunks
To print the number of free chunks available on an ext2/ext3/ext4 filesystem, you can use the e2freefrag
command with the -c
option and the desired chunk size in kilobytes. Here’s the code:
e2freefrag -c chunk_size_in_kb /dev/sdXN
Motivation: It is useful to know the number of free chunks available in a filesystem to understand how fragmented the free space is. By specifying the chunk size, you can determine if there are larger contiguous areas of free space or smaller scattered areas.
Explanation: The -c
option allows you to specify the chunk size in kilobytes. This determines the granularity at which the free space is analyzed. The larger the chunk size, the fewer chunks will be reported, providing a higher-level view of the free space fragmentation.
Example Output:
Free space on /dev/sdXN (chunk size: 512 KB):
Total free chunks : 36
In this example, the output shows that there are 36 free chunks of size 512 KB each. This information helps assess the fragmentation level by examining the number of non-contiguous free chunks.