Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Reboot into single user mode and run a manual fsck which will tell you the percentage of fragmentation.. majority of the time, I'd say 95% of the time you will never need to defrag your Linux drives, the Lnux filesystems are superior to Windows and don't get fragmented.
trickykid is right you shouldn't have to do this. In the past when I have asked about this I was told the only way to do it is to backup the file system remove it and recreate it then restore the data. I wouldn't worry about it I run a ton of servers for long periods of time and have never had a framation problem.
A defragmenting tool is actually quite difficult to implement. For performance, you have to try and keep files together that are likely to be accessed at about the same time, as well as just putting file fragments together and consolidating the free space. Also, you need to allow read/write access to the filesystem during this time, to prevent the need to take the machine offline. For performance, you also need to minimize the number of disk reads/writes, which is not an easy requirement to accommodate.
This is all much easier to do in the filesystem driver than it is in a user-space utility, so I doubt that we'll see a user-space defrag tool anytime soon; it's far more likely that we'll just keep seeing better and less fragmentey filesystems. I guess that Windows can't do this because of the need to support old legacy programs that access the disk directly.
The easiest and safest way to defragment a hard disk is still to take all the files off it and then put them back onto it again. Works every time.
However if ever i'm intrested in defrag is their a proper way from command line.
You need to have the partition unmounted as in boot up from a rescue cd.
For example: to run this on /dev/hdb1
You can run the command: e2fsck -f /dev/hdb1
You can try it without the -f ( force ) switch first. More commands with e2fsck --help
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.