If you thought that only the only NTFS and Fat systems were fragmented, then surely you will be surprised when reading these lines, and it is very common to think that this only happens with Windows, but in reality all file systems to a lesser or greater extent It will end up fragmenting, whenever new information is erased and written, “gaps” are created that will be filled with certain data that are of different sizes from each other, this being what produces fragmentation.
Certainly each file system has certain characteristics when it comes to dealing with fragmentation, my favorite is XFS not only because of its support with Red Hat, but in addition to this it is one of the best for larger partitions and that takes better advantage of 64-bit processors.
So let's start by checking the fragmentation status of the hard drive.
For this we will use a tool for XFS called xfs_db with this we can debug XFS eXtendedFileSistem_DeBuger In most cases this tool comes with the system if you use XFS, if not, we must install xfsdump.
Let's find out if we have xfsdump in Fedora 23
dnf search xfs
Last metadata expiration check performed —-.
================================================ ========================== S / N Matched: xfs =================== ================================================= ======
xfsdump.armv7hl: Administrative utilities for the XFS filesystem
xfsdump is the utility package that Fedora provides, in the case of Arch it is already integrated into the system.
To check the fragmentation status of an xfs partition, we will write this code:
xfs_db -c frag -r / dev /
The recommendation is that if it is greater than 10% proceed to defragment, if it is less then you can leave it for later.
Now, if we use "-c frag" the command that we are going to execute is sent to xfs_db just to consult, if we do not place the "-c frag" then it will place a promp so that we can execute queries and we will put "frag" on it, the fastest way would be:
xfs_db -c frag -r / dev / mmcblk0p3 actual 66155, ideal 65615, fragmentation factor 0.82%
As we see in the previous part, I have a degree of fragmentation of 0.82% since a few days ago I defragmented it, it was about 5% fragmentation.
Defragmenting the XFS partition
Now we proceed to defragment the partition, to begin we must execute xfs_fsr what is inside the package xfsdump that we installed previously; xfs_fsr means eXtendedFileSystem_FileSystemReorganizer, and your task is that, reorganize the XFS system.
So we write:
xfs_fsr -v / dev / mmcblk0p3 / start inode = 0ino = 1928extents before: 2 after: 1 DONE ino = 1928ino = 219417extents before: 2 after: 1 DONE ino = 219417ino = 219395—
Taking into account that depending on the degree of fragmentation, the time it takes to perform the defragmentation will be greater or lesser.
Once the process is finished, we review the degree of fragmentation again:
xfs_db -c frag -r / dev / mmcblk0p3
And this is the way to defragment XFS systems, if you have hard drives with Terabytes partitions and when reviewing the degree of fragmentation and it reaches 10%, after defragmenting you can see the difference.
excellent information !! thanks!! I was looking for this precisely and I found it here, keep up the good work !!
Regards…
And in debian how is it done, are they the same lines?
I would only add for the unwary that only file systems on hard drives should be defragmented. While defragmenting isn't going to kill a solid state drive, it does cause it to "wear out" prematurely.
regards
Nicolas Gabbo
Could I make another one for Ubuntu?
I'd like you to make one for Debian too.