Jump to content
naquaada

Limit disk fragmentation by using Disk Images - Firefox as example

1 post in this topic

Recommended Posts

Hi,

 

there's always a big fight if defragmentation of HFS+ is neccessary or not - it is, every filesystem fragments. The internal defragmentation system is only very limited. I'm using iDefrag sometimes on my boot partition, and it increases the speed of my HD. It's only useful because it sorts all system files to the beginning of the partition.

 

A big source for fragmentation are many small files, like they are produced in a browser cache. They are scattering all over the partition, probably removing large areas for bigger files. But OS X has a solution for this: disk images. If the browser cache is redirected to the disk image volume, the small files will stay there and not on the main partition. That reduces fragmentation, and if the disk image file is also not fragmented the access will be faster.

 

Here's a guide to modify Firefox to this method.

 

1. Open Disk Utility and create a disk image with fixed size (.dmg). Firefox allows 1 GB of disk Cache, so create it in a size that there are about 1.1 GB free. You can choose the path freely, it also can be on another harddisk, if you f.e. want to reduce access to your SSD. I'm using a folder 'Temporary' in my home folder. The name of the disk image and the volume name isn't important, I'm using 'FirefoxCache'. If you have more than one Firefox account, you have to double the image size, because Firefox uses 1 GB cache per account (I think ;-)

 

2. Drag the FirefoxCache.dmg in your start objects.

 

3. Open in Firefox a new tab and enter the special settings by entering about:config in the adress bar. Search for 'cache'. There should be two entries:

 

browser.cache.disk.parent_directory

browser.thumbnails.cache.disk.parent_directory

 

Set both to /Volumes/FirefoxCache. Now enter the cache settings in the Firefox prefs, disable automatic cache management and set the cache to 1024 MB. Now open the volume FirefoxCache, a folder 'Cache' should be created.

 

4. Actually you have the 'FirefoxCache' volume visible on your desktop. That's rather annoying, so let's make it invisible. You can do this with Path Finder, but it works from the Terminal, too. Use this command: chflags hidden /Volumes/FirefoxCache

It should work without sudo. You have probably to restart the finder to make it disappear. To make the volume visible again, there should be an option unhidden, but this doesn't work on my Leopard system.

 

5. There's a small problem. If the disk image wasn't open and Firefox is started, Mac OS creates a real folder 'FirefoxCache' in /Volumes to get a volume with this name. If the disk image is opened now, it will be mounted as 'FirefoxCache 1'. So it will never be use the disk image and still save the files to disk. So we have to make sure that there is no folder with that name in /Volumes. For this we can use the LaunchAgents function. Here's the script:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>com.MyLA.FirefoxCacheRemover.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>"rm -rf /Volumes/FirefoxCache"</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Save this file as 'com.MyLA.FirefoxCacheRemover.plist' and move it into /System/Library/LaunchAgents. This way it will automatically executed and deletes at every boot the folder /Volumes/FirefoxCache and all its contents. This works in Safe Mode,too. Best set the permissons of the LaunchAgent file to root/weel. You can read more about LaunchAgents here.

 

6. Of course it is useful to remove the cache, it could reach to more than 10.000 files. Because the volume is invisible, you can use the Finders 'Go To...' function. Use 'Shift-Alt-G' on a PC keyboard or 'Shift-Command-G' on a Mac keyboard. Enter '/Volumes/FirefoxCache' and you should see a folder named 'Cache' in it. You can quit Firefox and simply delete it. But this has the big disadvantage: All files are deleted by the trash, so it will take very long. Best is to do this from the Terminal, also quit Firefox first and use

 

rm -rf /Volumes/FirefoxCache/Cache

 

7. So, if everything works fine, you can remove your old Firefox Cache folder, the files are still there. Navigate in your home folder to /Library/Caches and search for Firefox. I don't know if you can delete the complete folder, but you can take a look in your Profiles folder and search for a folder 'Cache'. Delete it, do this as usual. In never versions of OS X the Library folder of your home folder is hidden so, so you have to use the 'Go To...' function again: Select your home folder in a Finder's window, open the 'Go To...' window and enter 'Library/Caches'.

 

 

I hope that was it. I'm using this method for a very long time now, with good results. The total number of files on my boot volume is smaller and I don't have too much small files with just a few KB on the drive, which are slowing down the drive.

 

naquaada.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×