Next up,
we're going to take a look at how we can defrag our data stored on our disk
because a major performance hinderer is fragmented data.
Over a period of time, especially with large files,
we might find that we can't write the rest of a file or new blocks of a
file in contiguous blocks to where it's currently stored.
Now this means then access to that data is going to be slowed
as we have to access more parts of the disk.
To speed access up, we can defrag the data,
but for this to work, generally,
we need to be making sure that we don't fill the disk by more
than 80% so we've got space to move data around.
When we're looking at defragmenting an EXT4 drive,
the default drive that we have for our root file system on Ubuntu,
we need to make sure that the extent feature is enabled.
When we go through then and run our dumpe2fs,
we get all of the metadata, in this case,
for device sda1.
When we go through and searching for extent, that should show in our features.
It should be enabled in newer versions of EXT4.
We can then go through and check to see if our root
file system needs to be defragmented, and if it does,
we could go through and then run our defrag just
missing out the option ‑c for our check.
Now of course, we could have other file system types on top of Ubuntu,
but we're going to jump across to defrag XFS on side of our
Alma Linux system as it has XFS by default.
Now defragmentation in XFS is known as file system reorganization,
hence, the command xfs_fsr.
Again,
we can go through and run this and see if we need to
fragment our root file system,
maybe we don't as it's a new file system as we haven't
done a lot on the Alma Linux system, but at least we know the tools.
But the best way to know the tools is to dive out to our command line,
and I do so encourage you to join me at the command line as we go through
looking at defragmenting our file systems.
So we can go through and check our free disk space.
Remember, we're really looking at keeping at least 20% free.
We can run our defrag on Ubuntu 2004 and run a defrag of our
XFS file system on our Alma Linux 8 system.
So when you're ready,
fire up your engines and I'm going to see you at the command line.
And here we are with our fingers in the glorious pixels
that we find on our Ubuntu 2004 system.
When I go through and do a mount ‑t for type and then ext4,
we can see then that the EXT4 file system we have is our root file system.
Now we know which file system is our EXT file system,
we can go through and run a sudo and dumpe2fs,
and if we take a look at /dev/sda1,
now we get a huge amount of metadata coming back from there.
So let's go through and clear our screen and then go
through and pipe to our good friend, grep.
Good afternoon, Mr.
Grep.
How are you?
With this on the command line,
we can go through and look then for extent and we can see
that becomes a file system feature,
and we can see it's listed as a feature of our file system so we are good to go.
But let's also go through and do a df ‑h to look at the free space that
we have available inside of our root file system.
And we can see with that we've got 9% in use,
so we've got plenty of space available.
Remember, we don't really want to be getting above 80% if we need to defrag.
If we now go through and look at sudo and e4 for extended 4 and then defrag,
we can go through and do a check on our root file system and
it will then go through and tell us really if we need to
defragment our root file system.
So as we go through then and check,
we can report to see that there is a little bit of fragmentation,
and we can see there is a little bit within our log file,
a little bit within our auth log file,
so especially the log files are being written to a lot,
and we really see the fragmentation is occurring
all within our var log directory.
When we take a look at this, we can see then that our fragmentation score is 0,
but it's actually giving us an idea that is not our problem,
and we can see if it becomes above 56, we need to fragment it,
so we don't need to defragment it, but if we did need to defragment it,
we'd just remove the ‑c for our check.
Moving across, if we take a look at our XFS file system,
the XFS file system has been built with fragmentation in mind,
but it's called file system reorganization.
So as such, we've got then our command xfs_fsr,
and we can then go through and take a look at our root file system.
And again, as we go through,
we can see then that we're not moving anything around.
So again, our file system is not fragmented,
but we are actually trying to defragment it at the moment,
but I say as far as the EXT4 is concerned,
we need to be using later variant, but with XFS, it has always been built with fragmentation in mind.