Firefox on RAM

From ArchWiki
Revision as of 09:49, 19 August 2009 by Graysky (Talk | contribs) (Created page with '==Introduction== If your machine has memory to spare, you can use tmpfs to cache your entire profile directory which makes Firefox very responsive and quite a bit faster. Doing s…')

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

If your machine has memory to spare, you can use tmpfs to cache your entire profile directory which makes Firefox very responsive and quite a bit faster. Doing so also greatly reduces the amount of disk writes your system preforms as you browse the web.

Backup your current profile(s)

Before doing anything, creating backups is always a good idea. This example shows only a single profile, but you can repeat the steps for each of your profiles if you have several. Tarup your profile as a backup:

$ tar zcvfp ~/firefox_profile_backup.tar.gz ~/.mozilla/firefox/y.default
Note: Replace y.default with the actual name of your profile directory.

Setup your /etc/fstab

Now setup an entry in /etc/fstab for the tmpfs using your favorite text editor. This example uses nano:

# nano /etc/fstab

Add the following line making the following replacments

  • x is your username
  • y.default is your profile's name
  • uid=1000 and gid=1000 should match the uid/gid for your user
firefox /home/x/.mozilla/firefox/y.default tmpfs size=128M,noauto,user,exec,uid=1000,gid=1000 0 0
Note: If you disire more than 128 Meg of space for your profile, use a larger value in this line

Enable the tmpfs and keep it sync'ed it via a script

To manage the tmpfs space for your profile and to ensure that your tmpfs profile stays sync'ed up with a copy on your HDD, use the following script.

#!/bin/bash
# Change this to match your correct profile
PROFILE="y.default"

cd "${HOME}/.mozilla/firefox"

if test -z "$(mount | grep -F "${HOME}/.mozilla/firefox/${PROFILE}" )"
then
    mount "${HOME}/.mozilla/firefox/${PROFILE}"
fi 

if test -f "${PROFILE}/.unpacked"
then
    rsync -av --delete --exclude .unpacked ./"$PROFILE"/ ./profile/
else
    rsync -av ./profile/ ./"$PROFILE"/
    touch "${PROFILE}/.unpacked"
fi 

exit

Save that in your scripts directory (I called mine tmpfs_firefox.sh) and make it executiable:

$ chmod a+x /path/to/tmpfs_firefox.sh

Notice that the script looks for ~/.mozilla/firefox/profile which is your profile's backup directory. Since tmpfs is literally present in your RAM, its contents will not survive a reboot, therefore it is mirrored in ~/.mozilla/firefox/profile by this script.

Copy your profile to ~/.mozilla/firefox/profile like so:

$ cp -a ~/.mozilla/firefox/y.default ~/.mozilla/firefox/profile

Now empty your "live" profile directory so tmpfs_firefox.sh can mount it to the tmpfs space, populate it with the contents of ~/.mozilla/firefox/profile and also keep it sync'ed for you. Close firefox before doing this!

$ rm -rf ~/.mozilla/firefox/y.default/*
$ /path/to/tmpfs_firefox.sh

That's it! If your run the script a 2nd time, it will sync your tmpfs profile with the copy on your hdd. This can be automated via a cron job for your user:

$ crontab -e

Add the following to kick off the script every 5 min:

*/5 * * * * * /path/to/tmpfs_firefox.sh