Ubuntu – Move Google Chrome cache from SSD to RAM
Running an SSD for the main boot partition is quite convenient for any OS, including Ubuntu. However having Google Chrome, or any browser, store its cache on the SSD is not the ideal scenario.
Under Ubuntu Natty 11.04 moving Google Chrome’s cache to RAM is fairly simple and only takes a few commands. The advantages to storing the web browser cache in RAM are: quicker reads/writes than on disk drives, no wear and tear on disk drives and the cache will be erased on reboot. The disadvantages are: the cache will be erased on reboot and will consume RAM, which can be limited on some systems.
1) Decide where to move the Chrome cache location to. I’ve picked the following location: /tmp/chrome.
This directory, /tmp/chrome will need to be created on boot and properly setup.
On Ubuntu 11.04 and probably older versions, this can be simply done in the /etc/rc.local file as follows:
sudo gedit /etc/rc.local
Add the following lines:
mkdir /tmp/chrome
mount -t tmpfs -o size=1024M,mode=0744 tmpfs /tmp/chrome/
chmod 777 /tmp/chrome/ -R
There are two ways to accomplish the next and last step. One is to create a symlink between the default google cache directory and the new temporary cache directory in RAM. The second is to add a switch to the google chrome command line telling each instance of the application to use our newly created cache directory in RAM.
1) rm -rf ~/.cache/google-chrome
ln -s /tmp/chrome/ ~/.cache/google-chrome
OR
2) Change the default here: sudo gedit /usr/local/share/applications/google-chrome.desktop
Replace the line:
#Exec=/opt/google/chrome/google-chrome %U
with
Exec=/opt/google/chrome/google-chrome –disk-cache-dir=”/tmp/chrome/”
The only adjustment some might want to make will be the size of the tmpfs partition created in RAM. I set the size to 1024MB as I don’t ever want to have to worry about it or adjust it. For systems with a lot of RAM the above size should not be an issue.
Used the following main sources:
Firefox & Chrome Cache on RAM Drive -Fedora / Ubuntu
How To Change Google Chrome’s Cache Location And Size
Can you help me change it back to the default? I’m running ubuntu 12.04 on an acer c7.
Sure. The removal process will essentially be the opposite of the installation process. For installing there are two main steps and for removing there will also be two main steps:
First, remove the tmpfs partition that is created on each boot by removing the three lines that were added to the /etc/rc.local file.
Second, remove either the symlink and/or the flag added to the chrome execution command.
Hope that helps!
any way to save and restore ram disk contents on shut down and startup ?
Seems technically feasible. One idea: Short script to copy contents to disk at shutdown and restore from disk location at boot