Perfect Ubuntu: Optimizing Your Browser with a RAM Disk

Every time I install Ubuntu Linux on a new computer I realize that I’ve forgotten how to do a bunch of configuration stuff that makes my computer experience so much more pleasant. To fix that, I’m starting a series of blog entries to document the tweaks (all to be tagged with “perfectUbuntu”. Here’s the first: optimizing Chrome, Chromium, and/or Firefox on Ubuntu Linux by using a RAM disk for its cache.  These instructions are for a single-user system.  If you have multiple users you’ll need to modify this a bit if you want it to work for each of your users, but if you’re running a multi-user installation you probably know enough to handle that without difficulty.

Applies to:  Ubuntu 10.10 (10.04 seems to need to use the “ramdisk” command in /etc/fstab instead).

First, make sure you want to do this. Do you have RAM to spare? I’m currently running on a 4GB system, so even when I run the occasional virtual machine I have plenty to set aside as a half-gig RAM disk. Also these instructions apply only to newer versions of Ubuntu (those running Grub 2). Open up a terminal and dive in:

1) Most of our commands require superuser privileges, so we might as well just switch to root.

sudo su -

2) Edit your startup script:

nano /etc/rc.local

Right above “exit 0″ we’ll add the commands that need to run each time at startup:

mkdir /tmp/ram

mount -t tmpfs -o size=512M,mode=750 tmpfs /tmp/ram/

chown -R yourUserName /tmp/ram/ (replace “yourUserName” with your user name)

Save the changes and exit (ctrl-o, ctrl-x).

3) Edit your boot configuration:

nano /etc/default/grub

Change the GRUB_CMDLINE_LINUX line to read:

GRUB_CMDLINE_LINUX=”ramdisk=512000″

and again save and exit.

4) Reboot and verify that /tmp/ram now exists with “drwxr-x—” rights with you as the owner.

5) Relocate your existing browser (no need to do this as root) cache and link to it:

For Chromium:

rm -rf  ~/.cache/chromium

ln -s /tmp/ram ~/.cache/chromium

For Google Chrome:

rm -rf  ~/.cache/google-chrome/

ln -s /tmp/ram ~/.cache/google-chrome

For Mozilla Firefox:

The cache for Firefox can be found inside your Firefox profile (which includes a big random string in it). As long as you only have one Firefox profile you can do this:

cd ~/.mozilla/firefox/*default

rm -rf Cache

ln -s /tmp/ram Cache

That’s it!  Restart your browser and you should notice a nice bump in speed as your browser no longer writes cached files to disk but keeps them in your RAM disk.  Much faster.  As an added bonus, your cache will clear at every reboot.