Using tmpfs for Security and Speed

I have 3.9GBs of RAM of which Ubuntu 10.04 (Lucid Lynx) hardly touches more than 512MBs so I'm going to move all my temporary files to RAM. This will result in 2 things:
  • Reading and writing temporary files will be much faster.
  • Temporary files will be more securely removed on shutdown.
Standard practice for Linux is to store temporary files in /tmp. A quick edit of the file system table (located at /etc/fstab) will make sure that the /tmp directory is mounted as a RAM disk using tmpfs. Open up /etc/fstab in an editor (vim, nano, gedit etc.) as a super user and append the following line:
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 2
Let's go over some of the syntax of the line we just entered. There are 6 parts to any fstab entry, each separated by whitespace:
  1. device: This typically names the device or partition being mounted through either a /dev address or a UUID. Since our entry isn't a physical device we can give it any arbitrary name, I've chosen tmpfs.
  2. mount point: This is where our new file system is attached to the root file system.
  3. type: This is the type of filesystem we're creating.
  4. options: These are options we're giving to the filesystem. The options I've provided are:
    • default: Default file system options
    • noatime: Linux will update the access time property of a file whenever it is read or written, something that is really only useful on servers or if you use mutt for your email. I add this option to most of my file systems for a small performance boost.
    • mode=1777: This will give read and write permissions to everybody.
  5. dump: If set to 1, dump will make backups of this file system. To not make backups we set to 0.
  6. pass: This is the order fsck will check each filesystem. 0 is skip, 1 is reserved for /root and 2 should be used for the rest.
This new mount point will be enable on next reboot.

Speed and security sounds like something I want Chromium to benefit from as well. To move Chromium's cache to our new tmpfs open up /usr/share/applications/chromium-browser.desktop. This is the configuration file for how Chromium appears in menus and is launched. Near the bottom will be a line starting with Exec similar to:
Exec=chromium-browser %U
Change this to:
Exec=chromium-browser --disk-cache-dir="/tmp" %U

Now to make Firefox use our new RAM disk to store it's temporary files go to about:config and add a new string entry for
and enter:

Credit goes to Fewt for inspiring this article, though he goes a little further by also moving logs to RAM, which doesn't seem the safest thing to do, but hey, whatever you want to do with your system...


Post a Comment