So here's one way to compile a list of files on your computer along with the number of extents they take up:
PHP Code:
Code:
./spool/mail/demonslayer: 0 extents found |
I cordially suggest that you are trying to solve a "problem" that really doesn't need solving.
Fragmentation was a genuine problem when disk drives were much smaller than they are today; and, much slower. Operating systems (e.g. MS-DOS, having been originally designed for floppy-disk drives and computers having no RAM to spare, were not terribly sophisticated about file placement and disk-I/O, and, quite frankly, could not then afford to be. These days, yes, you might discover that "OMG, this drive is really fragmented!" But ... is that making a pragmatic, measurable, demonstrable impact on actual production performance? If it isn't (and it probably isn't...), then, "Houston, we do not have a problem." |
Yes, so far, it doesn't seem to be a problem. However, it would be cool to make a defrag script to find heavily fragmented files and copy them to fix it. I'm almost there, I just need to sort the output efficiently. I'll get to it later because I'm busy now, but if someone can help it would be great.
|
Quote:
Code:
cat $output | awk '{printf("%s %s\n",$(NF - 2),substr($0,1,match($0,/: [0-9]* extents? found/)-2))}' | sort > $output.sorted |
It almost works, but there were a few bugs, so here's what I will use:
Code:
cat defrag | awk '{printf("%s %s\n",$(NF - 2),substr($0,1,match($0,/: [0-9]* extents? found/)-1))}' | sort -n |
Here's the root script I wrote, it seems to work ok:
DISCLAIMER: It is dangerous to run scripts as root, especially ones that make changes. This script is released as is, and there is no warranty whatsoever. Also, do NOT run this script when the disk is almost full. It will not only not work, but strange things may happen. PHP Code:
There's also two more scripts for doing this as a user and not messing up permissions, I'll release those if I can't find a better way to do it. |
It seems to run ok, now does anyone have an idea on how to make the 'cp' and 'mv' steps safer against stopping the script at the wrong time ? Should I use nohup ? or something else ?
|
Ok, I added support for a threshold, where you can specify the threshold number of extents above which it will defragment files. I've also made local user scripts so that they don't mess up permissions. Make sure to change the scripts as needed to work on your system (especially your home directory). I uploaded them to my site:
http://htexmexh.my3gb.com/linux/scripts.html I guess I'll mark this solved now. |
There is a problem with the script that I did not take into account. If you use lilo, do NOT include the boot directory in the directories for loop, so change:
Code:
for i in bin boot etc lib lib64 opt root sbin usr var Code:
for i in bin etc lib lib64 opt root sbin usr var |
All times are GMT -5. The time now is 02:51 PM. |