Source distrowatchJesse Smith@Distrowatch a écrit :
Checking file system fragmentation
Reorganizing-my-hard-drive asks: When I was running Windows I used to defrag my hard drive once a month to keep performance up. I have heard that it is not necessary to defrag the drive under Linux, is that true and how do I defrag my Linux drive if I want to?
DistroWatch answers: Most file systems that Linux will support, such as ext4, XFS and Btrfs, will generally avoid fragmenting your files automatically. A hard drive gets fragmented when the operating system writes part of a file in one location and another part of the same file in a different location. This breaks up files and causes pieces of large files to be scattered around the hard drive. On spinning drives this results in poorer performance as it takes longer to access all the various pieces of the file. Linux file systems generally attempt to write data to the hard drive in a way that keeps the parts of the file together.
Sometimes, usually when the hard drive is close to full (around 80% or 90% of its capacity) files may become fragmented as the system runs out of convenient places to write large files in continuous blocks. But when the disk is less than 80% full, a Linux file system will generally avoid fragmentation.
While most people do not need to worry about their Linux file system becoming fragmented, there are tools for dealing with fragmentation. As each file system works a little differently, there are different utilities for dealing with fragmentation on each file system.
The most commonly used file system on Linux is probably ext4. If you would like to check to see if your ext4 file system is fragmented you can run the following command as the root user or via sudo:The above command runs the ext4 defrag command. The -c option tells the program to check for fragmentation. This will cause the e4defrag program to look for fragmentation, but not attempt to repair it if any is found. The last parameter, / in this example, is the location of the file system. In our example we are checking the root (/) file system, but we could also check our /home directory usingCode : Tout sélectionner
e4defrag -c /
The e4defrag command will produce a "fragmentation score". A score in the range of 0 to 30 indicates there is no problem. A file system with a score of 31 through 55 is slightly fragmented, but the fragmentation can probably be ignored. A score of 56 or higher suggests the drive should be defragged. We can defrag the drive by running the same e4defrag command again, this time without the -c option.Code : Tout sélectionner
e4defrag -c /home
Different file systems use different commands, most of them feature more options than the e4defrag command and I recommend reading their respective manual pages. The command to defragment a Btrfs volume mounted at /home is as follows:Code : Tout sélectionner
e4defrag /home
If you are running a system with XFS as one of the file systems, you can defragment all connected XFS partitions by running the commandCode : Tout sélectionner
btrfs filesystem defrag -r /home
These defrag commands may never need to be run as each file system generally keeps itself well organized. However, if you want to experiment to see if your file system can be better organized, these above commands will do the job.Code : Tout sélectionner
xfs_fsr
Franchement j'ai été surpris à la lecture de cet article. Mais bon, vu que j'ai une tendance compulsive à changer d'OS, je n'ai pas trop le temps d'avoir un disque fragmenté....