4 ms·
"If you do have problems with fragmentation on Linux, you probably need a larger hard disk. If you actually need to defragment a file system, the simplest way i
by trentmb 14y ago
"If you do have problems with fragmentation on Linux, you probably need a larger hard disk. If you actually need to defragment a file system, the simplest way is probably the most reliable: Copy all the files off the partition, erase the partition, then copy the files back onto the partition. The file system will intelligently allocate the files as you copy them back onto the disk."
So... buy a larger hard disk, or get a second disk to copy everything to instead of a defrag utility?
I think I'll take the Windows approach here.
- dunecn 14y agoWell, in that case, Windows can't do any better. In order to defrag a filesystem, that requires free space to copy and move files around. If that space isn't there (because the HDD is nearly full), there isn't much you can do.
- tzs 14y agoThe Windows defrag API allows you to work at the cluster level. You only in theory need a single free cluster in order to defrag.
- cavilling_elite 14y agoAt this rate, it would be faster to move everything over to a new harddrive.
- deleted 14y ago[deleted]
- ZoFreX 14y agoIt's worth noting that while the Windows defrag utility is completely useless without a lot of free space available, many of the third party defrag tools can still work (albeit much more slowly) in that situation. Of course with SSDs becoming more and more prevalent, this is becoming a non-issue anyway.
- toemetoch 14y agoI'm a bit puzzled by the second method (with the partition swipe and copy back) . So, linux scatters the files. My partition is almost full and fragments. Now I copy all the files to a second location and wipe the partition. Now I copy them all back. Won't that just scatter all the files and fragment all over again ?!?
- dredmorbius 14y agoIn the first case, the file create & scatter may have occurred in stages, leaving less optimal disk utilization. By copying files back en mass, fragmentation / allocation will be more optimized. If you have insufficient disk overhead and continue the file destruction/creation process, you may end up with higher levels of fragmentation in future. This depends on your particular usage scenario. If you're not underallocating disk, generally you won't have much of a problem.
- gillianseed 14y agoWell there must be some mistake in what he wrote, you don't have to 'wipe' the partition, merely remove the files (and directories if any) which you copied over before copying them back. When you copy the files 'back' they will be copied sequentially and thus be placed 'scattered' (as in position on harddrive, not fragmented file) with appropriate space left between them for possible growth without needing to fragment them. This copy method can of course be done on Windows aswell, the only difference is that NTFS's file placement strategy generally results in more fragmentation over time than the strategies employed by Linux filesystems like ext(x). That said all filesystems get fragmented over time, no strategy can avoid this fully. Also if your partition is very fragmented and you have many large files it can be faster to use this 'copy to another partition' method rather than using a defragmenter which will operate solely on the target partition and thus need to move many parts of files around in the partition to 'fit' in parts of other files. Of course using the copy-method requires you having another partition with enough free space so it might not always be a feasible option.