Defragmenting an Ext4 File System

You can defragment the file system to increase I/O performance.

Ext file systems can become fragmented over time, leading to performance degradation. Defragmentation helps to ensure that files use contiguous disk blocks which improves overall system efficiency.
  1. Identify fragmented files by using the e4defrag -c command.

    For example, to view the fragmentation on the device /dev/sda1, run:

    sudo e4defrag -c /dev/sda1
  2. Defragment files, directories, or devices with the e4defrag -v command:
    To defragment specific files or directories, you can run:
    sudo e4defrag -v /path/to/file_or_directory

    You can also defragment an entire file system by specifying the device path:

    sudo e4defrag -v /dev/sda1
  3. Verify defragmentation status by running the e4defrag -c command again.