After a solution for a different problem, found in the following thread, I now have a very "quick" Firefox on my laptop, which I am in love with: »
[SOLVED] Have a script run when a program is closed?Ah, success! Which on Linux is a very rare thing, indeed! (Just a joke, everyone. A harmless jab.)
Thank you for your help, once again, pablo
! For the sake of documentation, in case anyone else is interested, I'll write down what I did to speed up Firefox 3.x and minimize the number of times that it reads/writes to the hard disk (or even to the SSD, for those special netbook users out there.) These steps are based on what was written in the ArchWiki page as well as pablo's help.
I really recommend anyone who is using a netbook, especially one equipped with an SSD, to try this out for yourself. I've read around that Firefox 3.x (using SQlite database files for bookmarks, history, etc) can freeze up and feel "sticky" and "slow" on an SSD disk. Make sure you have enough RAM to spare before trying this trick. (My laptop has 2 GB, and my netbook has 1 GB total RAM.)
STEP 1) Re-locate Firefox's Cache folder to the built-in RAMdisk folder (optional, see discussion below, or use STEP 4 instead) * Open up Firefox and clear your temporary files
* In the URL bar, type
about:config and create a new string called
browser.cache.disk.parent_directory and make its value
/dev/shm/ff-cache* This means your Firefox Cache contents will now be saved in
/dev/shm/ff-cache/Cache with the same permissions as before
* Anytime you shutdown or reboot the system, these files will disappear, which to me is fine, since I empty my browser cache more often than I reboot. Besides, these are unimportant files that are not critical to save between reboots
* The amount of RAM taken up will not exceed whatever you limited Firefox's cache to in your preferences. (Edit > Preferences > Advanced > Network)
STEP 2) Backup your profile folder, just in case* Your Firefox profile folder (which houses all of your settings, bookmarks, history, add-ons, etc) is located at:
~/.mozilla/firefox/ and will be named
xxxxxxxx.default, where
xxxxxxxx will be a unique random string of characters
* ArchWiki provides a simple solution of backing up this folder to a .tar.gz archive in your home folder by running the following command in a terminal:
tar zcvfp ~/firefox_profile_backup.tar.gz ~/.mozilla/firefox/xxxxxxxx.default* Replace
xxxxxxxx with the correct string of characters
STEP 3) Create an fstab entry for the profile RAMdisk* Edit
/etc/fstab and add a line at the bottom that reads like this:
firefox /home/username/.mozilla/firefox/xxxxxxxx.default tmpfs size=128M,noauto,user,exec,uid=1000,gid=1000 0 0* Replace
username with your actual username
* Replace
xxxxxxxx with the actual profile string of characters
* Replace
128M with your desired size of the RAMdisk. The more available RAM you have, the more liberal you can be with this value. I found that 100M is more than plenty, especially since my Cache is no longer saved in my profile, anymore. (I am using 20 MB in the RAMdisk, as we speak)
* Replace
uid=1000 and
gid=1000 with your respective user and group numbers, or even with your actual username and group name. For example:
uid=dave,gid=users* Remove the option
noauto if you wish for this mount to take place upon booting up your machine. This also helps if your user account does not have sudo privileges for the
mount command
STEP 4) Create a separate fstab entry for the Firefox cache (use this if STEP 1 was skipped)* Edit
/etc/fstab and add a line at the bottom that reads like this:
ff-cache /tmp/ff-cache tmpfs noexec,nosuid,nodev,noatime,size=50M 0 0* Change
size=50M to match the setting in Edit > Preferences > Advanced > Network
* As root, mount the new RAMdisk:
mount /tmp/ff-cache* Open up Firefox, and in the URL bar, type
about:config and create a new string called
browser.cache.disk.parent_directory and make its value
/tmp/ff-cache* You now have your Firefox cache mounted in RAM
* To check the available space / used space on the
/tmp/ff-cache RAMdisk, type:
df -h | grep Filesystem && df -h | grep /tmp/ff-cacheSTEP 5) Create the sync script, which syncs the profile in the RAMdisk (volatile) to one on your hard disk (permanent)* In a text editor, create a file called
ramdisk_firefox_sync.sh and save it somewhere convenient, such as a
Scripts folder in your home directory
* Make it executable:
chmod +x ramdisk_firefox_sync.sh* Paste the following into the file, and make sure to replace
xxxxxxxx with the actual string of characters for your Firefox profile folder:
#!/bin/bash
# Change this to match your correct profile folder name
PROFILE="xxxxxxxx.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 -a --delete --exclude .unpacked ./"$PROFILE"/ ./permanent_profile/
else
rsync -a ./permanent_profile/ ./"$PROFILE"/
touch "${PROFILE}/.unpacked"
fi
exit
STEP 6) Prepare the permanent profile folder* Copy everything stored in the current profile folder to a new folder called
permanent_profile:
cp -av ~/.mozilla/firefox/xxxxxxxx.default ~/.mozilla/firefox/permanent_profile* Delete everything in the current profile folder (which will become the mount point of your RAMdisk profile):
rm -rfv ~/.mozilla/firefox/xxxxxxxx.default/** Make sure to replace
xxxxxxxx once again, with the proper string of characters
STEP 7) Mount the RAMdisk for the first time* Make sure your user has sudo mount privileges
* In a terminal, run the
ramdisk_firefox_sync.sh script:
~/Scripts/ramdisk_firefox_sync.sh* Now you have a mirrored copy of your profile loaded into a mounted RAMdisk. This step does not need to be repeated, as simply running Firefox will do this automatically from now on
STEP 8) Create a new launcher for Firefox* In the same
Scripts folder as before, create a new file called
firefox_ramdisk_profile.sh* Make it executable:
chmod +x firefox_ramdisk_profile.sh* Paste the following into the file:
#!/bin/bash
# Before launching Firefox, sync hard disk profile to RAMdisk profile, via the ramdisk_firefox_sync.sh script
~/Scripts/ramdisk_firefox_sync.sh
# After syncing, launch Firefox
firefox &
# Wait for Firefox to exit
wait
# Upon exiting Firefox, sync the RAMdisk to hard disk, once again
~/Scripts/ramdisk_firefox_sync.sh
exit
STEP 9) Change the value of your menu's Firefox entry to point to your new script, rather than just the command firefox* Open up your menu editor (in GNOME this is done with the command
alacarte or running
Main Menu / Menu Editor from your menu)
* Find the entry for Firefox, and replace the command
firefox with
/home/username/Scripts/firefox_ramdisk_profile.sh* Make sure to replace
username with your actual username
You should be all set now. I cannot say how well this will work out for you, since I have only tried it on two computers. (One running openSUSE, and the other running Linux Mint. I will soon try it on Ubuntu on my netbook, which needs this trick the most!) You will notice I didn't bother to include the additional steps of creating cron jobs or system startup scripts, since I feel they are not needed anymore. All the syncing is done when opening and closing Firefox, so the extra scripts would be redundant.
To summarize, every time you launch Firefox, your entire profile will be loaded into RAM. (Using this trick, your profile safely sits in a folder called
~/.mozilla/firefox/permanent_profile, which gives you a permanent copy of your profile that survives between reboots.) Since your entire profile is completely loaded into RAM, operations are quicker, such as browsing through your bookmarks and history, as well as sorting items, and using the URL bar (which is noticeably slower in Firefox 3.x, compared to Firefox 2.x) due to the use of SQlite database files. After exiting Firefox, the sync process happens once again, and any changes made in your RAMdisk profile (bookmarks, history, cookies, settings, etc) will be saved to the hard drive, for safe-keeping.
If you have an SSD drive, this should eliminate the hiccups associated with Firefox 3.x. Even if you do not use SSD, this decreases the number of reads and writes to the disk (since there is no disk activity while
using Firefox; only when launching it or exiting it.) If you try this trick out, let us know how well it works for you, or if there are any tweaks that can be made!
If you find any mistakes in this post, don't be shy to correct them! I am not very technically savvy, so I might have made a boo-boo in my train of logic.
Here is the ArchWiki page I used as a reference: »
wiki.archlinux.org/index ··· ng_tmpfsUPDATE: Fixed a typo in
STEP 9.
UPDATE: Added an additional step (now
STEP 4) on configuring another RAMdisk exclusively for Firefox's cache, rather than using the (optional)
/dev/shm location.
UPDATE: I removed the
-v (verbose) argument from the sync script in
STEP 5, since it is pointless in a GUI launcher. (There is nowhere for it to output, since it is not being run from a terminal, but rather from your menu shortcut.)
UPDATE: I recommend creating a cron job or script that periodically makes a backup copy of your Firefox profile folder. This is not required, but it is highly recommended, just in case something goes wrong. At least you will have a working copy of your Firefox profile and bookmarks, rather than nothing at all. I also recommend the
Xmarks addon for Firefox, which allows you to backup and sync your bookmarks on their server (or your own WebDAV server).