+5 votes
366 views
How to defragment hard disk in Linux

in Linux / Unix by (552k points)
reopened | 366 views

1 Answer

+3 votes
Best answer

1. Defragment the hard drive using e4defrag in Ubuntu Linux
2. Defragment the hard drive using FSCK in Ubuntu Linux

When managing and having Linux operating systems under our responsibility, it is ideal to understand and carry out frequent maintenance tasks to optimize their use..

Although there are differences between the best known systems, Windows, Linux or macOS, there are tasks that are standard and one of them is hard disk defragmentation.

The hard disk is one of the hardware elements that have more work on the computer since the operating system, programs and applications are installed there, it is used to backup data and many more tasks..

It is important to perform this task periodically since any file we see is itself a composition of several fragments stored in various areas of the hard disk.

There is a bad idea today that files from systems such as JFS, ZFS, XFS or ReiserFS do not require defragmentation, there is nothing more wrong because, although it is different from the Windows NTFS system, hard drives in Linux using any of these systems Files are also gradually affected by the location of the files locally..

We remind you that it is important to carry out this task with some time to optimize the useful life and speed of access to the disk for both reading and writing.

Today we will see how to defragment a hard drive in Linux.

To keep up, remember to subscribe to our YouTube channel! SUBSCRIBE


1. Defragment the hard drive using e4defrag in Ubuntu Linux

Step 1

This utility is part of the Linux operating systems and is a part of the e2fsprogs tool suite, but if it is not available we can run the following for installation:
 sudo apt-get install e2fsprogs 

image

Step 2

Once installed we can see the use of e4defrag by executing the following line:
 sudo e4defrag 

image

Step 3

We can list the partitions of our team by executing the following:
 sudo fdisk -l 
image
Step 4

Now, with this tool we have the option to defragment only one or more files using the following syntax:
 sudo e4defrag “Route to analyze” 
image
Step 5

But we can also, being perhaps the most important issue, the defragmentation of our disk drive. For this we have these options:
Defragment the unit without disassembling it
If we do not want to carry out the process of disassembly of the unit we can execute the following line:
 sudo e4defrag / 
This will start the process of analysis and defragmentation of all units available in the system: image
Defragment the unit by disassembling the units
The next option is to disassemble the units for a more detailed analysis of them. To disassemble the units and carry out the process we will execute the following:
 sudo e4defrag / dev / * 
image

2. Defragment the hard drive using FSCK in Ubuntu Linux


It is advisable to use this command from a live CD with the dismantled drives since doing so directly can affect the data stored there.
Step 1

For use, we can execute the following:
 fsck -fn / dev / sda1 
image
Step 2

There we can replace / dev / sda1 with the desired route. As an option we can execute fsck in safe mode without affecting the files using the -n parameter, for example, in an ext4 file system we execute the following:
 sudo fsck.ext4 -fn / partition path 
With these methods it will be possible to defragment hard drives in Linux environments and thus optimize their use.

by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Oct 6, 2019 in Linux / Unix by backtothefuture (552k points) | 224 views
+3 votes
1 answer
asked Sep 28, 2019 in Windows 10 by backtothefuture (552k points) | 330 views
+3 votes
1 answer
asked Nov 14, 2019 in Linux / Unix by backtothefuture (552k points) | 416 views
+3 votes
1 answer
asked Nov 5, 2019 in Security by backtothefuture (552k points) | 368 views
+3 votes
1 answer
asked Oct 22, 2019 in Linux / Unix by backtothefuture (552k points) | 252 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users