LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Best way to defragment hard drives in Linux? (https://www.linuxquestions.org/questions/linux-software-2/best-way-to-defragment-hard-drives-in-linux-4175674308/)

Arct1c_f0x 04-30-2020 01:48 PM

Best way to defragment hard drives in Linux?
 
Hey I have a bunch of drives and I have a feeling several of them are very fragmented. You know, part of a large .mp4 is stored here and part is stored there, and when navigating through one folder, the files in that folder are spread out all through the drive. How do I correct this? Is there any open source software out there that can help me?


Thanks!

shruggy 04-30-2020 01:59 PM

Defragmenting an SSD is not such a good idea though.

sevendogsbsd 04-30-2020 02:00 PM

I suppose it would depend on the file system in use (there are many) but I am pretty sure this is not necessary. Others may chime in and correct me. Keep in mind that Microsoft (IMHO) has developed terrible file systems and users have grown used to dealing with their idiosyncrasies. I have been using various Linux and BSD file systems for over 2 decades and have not defragged a drive in that entire time. I do "TRIM" on SSDs but my file system takes care of that for me and I don't have to do it manually. Not sure how this relates to fragmentation.

Again, someone that knows way more about this will I am sure add to this...

dugan 04-30-2020 02:03 PM

Quote:

Originally Posted by Arct1c_f0x (Post 6117757)
Hey I have a bunch of drives and I have a feeling several of them are very fragmented. You know, part of a large .mp4 is stored here and part is stored there, and when navigating through one folder, the files in that folder are spread out all through the drive.

What gives you this feeling?

Also, if this is an SSD, then keep in mind that this would have no impact on performance even if it were true.

shruggy 04-30-2020 02:06 PM

An old, but still relevant explanation. And the follow-up.

Arct1c_f0x 04-30-2020 02:49 PM

Okay so the drive I'm talking about is a mechanical 6TB drive and its housed in a external case (if that's at all relevant). I connect it to my pc by way of a USB 3.1 cable and then read documents off it or watch movies. It makes odd sounds sometimes when reading a movie like there's some sort of hesitation on the part of the drive.

Another question I have is:
Will watching movies and reading documents off the drive directly limits its overall life? So what I mean is reading the content on the drive as opposed to writing it.

sevendogsbsd 04-30-2020 02:58 PM

Mechanical drives under Linux filesystems do not suffer from fragmentation. That's what the link shruggy posted states, in essence.

Using a drive at all shortens its life but what good is a drive if you don't use it...make backups if there is any doubt of the drive's reliability.

Some drives make a little noise when reading and writing some are silent. My NAS drives make noise from time to time and it's normal. I have backups so if a drive fails, I can replace it and restore the data.

EDIT: what file system is the drive using? Is it NTFS or a Linux file system?

Arct1c_f0x 04-30-2020 03:12 PM

Quote:

Originally Posted by sevendogsbsd (Post 6117794)

EDIT: what file system is the drive using? Is it NTFS or a Linux file system?

The drives are using ex3/ext4 with Luks encryption

sevendogsbsd 04-30-2020 03:16 PM

OK, then defragmentation should not be required.

Arct1c_f0x 04-30-2020 03:21 PM

Quote:

Originally Posted by sevendogsbsd (Post 6117803)
OK, then defragmentation should not be required.

Thank you! I'm reading the document the other guy posted right now in order to gain more of a technical understanding of why it doesn't require defraging.

Thanks again for the help. How do I give rep points?

sevendogsbsd 04-30-2020 03:22 PM

I think there is a little icon to the right of the penguin under my name. Thanks! It was a team effort really: shruggy had the article :)

jefro 04-30-2020 03:34 PM

It is very possible that one may need or want to defrag. Linux filsystems in some cases may need it.

sudo e2fsck -fn /dev/sdax may offer clues on UNmounted drives.

Copy files off and copy them back to newly formatted much like the old ntbackup.

e4defrag may be installed already.

sudo e4defrag /

Arct1c_f0x 04-30-2020 03:40 PM

Quote:

Originally Posted by jefro (Post 6117808)
Copy files off and copy them back to newly formatted much like the old ntbackup.
/

It makes sense to me somehow why that would work and be a form of consolodation of files of the same directory in one place, but I don't know why.
So let's say I finished adding all the movies I wanted to a certain movie database and I was done adding files to that directory. At that point I would want to copy that movie database to drive B, reformat drive A back into ext4 and then copy the directory back to Drive A from drive B?

Is that the general idea?

rkelsen 04-30-2020 04:35 PM

Best way to defragment hard drives in Linux?
 
Yes it is... but don't be surprised if you don't see much improvement. While you can defragment drives in Linux, it is generally not necessary. They defragment themselves with use.

Modern NTFS no longer requires defragmenting either, unless you want to shrink a partition.

Accessing a large, mechanical, encrypted drive over USB is always going to be slower than if it were SATA.

Arct1c_f0x 04-30-2020 04:50 PM

Quote:

Originally Posted by rkelsen (Post 6117831)
Accessing a large, mechanical, encrypted drive over USB is always going to be slower than if it were SATA.

I totally agree but I can't find an eSATA to USB cord for less than $50 and I want this particular drive to be an external drive. Know any cheaper sources for a eSATA to USB cord?


All times are GMT -5. The time now is 08:28 AM.