Daily Ubuntu / Linux news and application reviews.


tmpfs is a virtual, RAM-backed filesystem. It’s lightning-fast, but since it’s RAM-backed, any file written to tmpfs uses precious memory while it’s there, and the entire contents of the virtual partition are lost on shutdown or crash. The good news is that these detriments can be minimized, making tmpfs a viable choice for your profile directory. This document gives some tips on how to mount your Firefox profile in a tmpfs partition while minimizing the downsides of tmpfs.

Let's see how to mount your Firefox profile to RAM to speed things up!

1. Reduce the size of your profile.

To reduce the size of your Firefox profile (so less RAM is used), enter "about:config" in the Firefox addrss bar and make the following changes:

set browser.cache.disk.capacity to 20000 or thereabouts 
set browser.safebrowsing.enabled to false 
set browser.safebrowsing.malware.enabled to false

2. Create an initial archive of your Firefox profile and create the fstab entry

Firstly, let's create an archive of your Firefox profile:
cd ~/.mozilla/firefox 
tar cpf packed.tar abcd1234.default
Replace abcd1234.default with your profile folder name in the command above and all of the following where you'll see this.

Now let's edit /etc/fstab:
gksu gedit /etc/fstab

And add the following line:
firefox /home/andrei/.mozilla/firefox/abcd1234.default tmpfs size=300M,noauto,user,exec,uid=1000,gid=100 0 0

Make sure you replace the path with the correct path to your profile. You can also change the size from 300M if you have enough RAM.

3. Create a script that backs up and restores your Firefox profile.

Since the Firefox profile is loaded in the RAM, you need to copy it from time to time (we'll cover the technicalities further below) to the hard disk and for this we'll use a script. Create a new empty file called ".pack_ffox.sh" in your home folder and paste the following:


# Change this to match your correct profile 

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

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

if test -f "${PROFILE}/.unpacked" 
    tar --exclude '.unpacked' -cpf packed.tmp.tar "$PROFILE" 
    mv packed.tar packed.tar.old 
    mv packed.tmp.tar packed.tar 
    tar xpf packed.tar &&\ 
    touch "${PROFILE}/.unpacked" 

Then, make it executable:
chmod +x ~/.pack_ffox.sh

After this, you'll need to quit Firefox so open this guide in another browser or copy it to a text editor so you can follow the next steps without having Firefox open.

4. Let's run the script

Make sure Firefox is closed, then empty your Firefox profile folder. You can either remove the folder contents or move the files somewhere else. We have an archive of your Firefox profile created under step 2.

Now, run the script:

In my test, the first time running the script, it might not work so if you get an error, run it again. Now, verify that the Firefox profile has been successfully mounted in the RAM and if an ".unpacked" (hidden) file exists in your Firefox profile directory. You can run:
which should list all the mount points, including the newly added Firefox profile.

Now you have to run the script again, but this tile check your ~/.mozilla/firefox folder and see if there's a new "packed.tar" file and an "packed.old.tar" file as well.

If both of those things checked out, you're clear to start Firefox again.

Since the Firefox profile is now using tmpfs, you'll need to copy it periodically to the hard disk, so the changes aren't lost. There are various ways of doing this, but the best way is probably to add a cron job that runs our script above every 5 minutes or so. To do this, run the following command:
crontab -e

And add this line (assuming you've used the script name which we've recommended above and placed it in your home folder):
*/5 * * * * $HOME/.pack_ffox.sh

Wait for 5 minutes, then check the "packed.tar" creation time, to see if it has changed (right click it, select Properties and see there) - it should have changed!

That's it!

via gentoo.org forums
Newer Post
Older Post