How do I defragment NTFS drives in linux

Asked by Sidarth Dasari on 2008-03-19

I have a headless home server running with 3 NTFS drives attached. Is there a way to defragment these drives? A command line app would be preferred.

Question information

English Edit question
Ubuntu coreutils Edit question
No assignee Edit question
Solved by:
Sidarth Dasari
Last query:
Last reply:
Jim Hutchinson (jphutch) said : #1

This might not be all that easy to do. Most people with NTFS drives also have windows and can do it that way. A couple potential solutions are and but I don't know if they support defrag. Another, albeit less enjoyable, solution is to copy the data off, reformat and then copy back. There may be a native Linux tool to defrag and if so hopefully someone will reply.

I have a NAS device that "looks" like a windows share so it works with windows but is actually Linux driven with a Linux FS so no defrag needed. I wonder if something like that would be an option. Out of curiosity, why are you using NTFS if you don't have windows?

Sidarth Dasari (sirsid) said : #2

Its just a leftover from when I did have windows. The drives are only used to store things on my home server now. If I did reformat them into a more linux compatible format, would I still be able to share them over my network to my other windows PCs?

Jim Hutchinson (jphutch) said : #3

Good question. I'm not sure but my hunch is yes. I have a WD NAS that uses Linux FS but has a front end (not sure if it's hardware or software) that make it act like a windows share. My guess is you can set up something similar but I have no idea how. I'll do some looking and let you know if I find anything.

Sidarth Dasari (sirsid) said : #4

Ah thanks. I appreciate it

Jim Hutchinson (jphutch) said : #5

I didn't know samba went both ways but it looks like maybe that's the answer. This article has some info on it. Scroll down a ways to get to the "Accessing Linux files from Windows" section. It's a pretty old article but maybe the samba approach is still the answer.

Sidarth Dasari (sirsid) said : #6

Thanks again. Ill try it out

This would be very useful to have on a live CD. In theory if you had access to a windows system drive you might be able to run a defrag from within wine ?

As an aside, my employer too does not allow us to defrag our windows drives from within Windows. This can also be a risk if the drive (or partition) is subject to third party encryption.

So currently there are other options :

a) remove the drive and mount it on a Windows (even if it's a junker) machine for defrag.
- dd a full backup copy somewhere first.
b) if you need to minimise downtime, dd the drive and defrag the copy.
c) dd the drive to a SSD and use that instead.

Mind how you go, don't get yourself fired, and try not to break any laws....

Additionally, defragging from another windows machine may be quite complex if you don't have and cannot synthesise permissions over the files concerned.

Suggest then a "turnaround" copy to temporary drive to repartition all drives as EXT2 (if static) or EXT3. This could be done over USB or eSATA if you have the patience.