1

OS: Linux Mint 19 Cinnamon 64-bit.


I know how to create a RAM disk (tmpfs), actually I have it mounted in /etc/fstab like so:

none    /ramdisk    tmpfs    size=2G,mode=0777    0    0

As you can see, it has 2 GiB, and is accessible to all users on my personal computer it does not matter anyways.


I know about --disk-cache-dir Google Chrome option. But I don't want to use it.

Reason being, I want to be able to run Chrome in whichever way I like, having the same RAM cache directory. There are simply too many ways I run my Chrome. What if I replaced an icon for instance? It is unusable for me at least.


I seek guidance on creating a shell script, which would create a symlink to Chrome cache directory onto my RAM disk, which is mounted as seen above.

That script I intend to put into root's cron using sudo crontab -e as follows:

@reboot /home/vlastimil/Development/sh/google-chrome-cache-ramdisk

Note, that I don't have a swap enabled on my system.

0

2 Answers 2

1

What you are looking for is https://aur.archlinux.org/packages/profile-sync-daemon/ which automates the process.

0

Supposing you have your RAM disk (tmpfs) mounted at boot time in /etc/fstab, you can do it as follows:

  1. First, make sure your script will exit on errors, this is important, don't skip this step.

  2. I recommend you start with constants definitions for an easy maintenance.

  3. I believe, but am unsure - feel free to correct me - you need to use absolute paths of commands since you intend to run the script from crontab.

  4. Actually, it appears, the command -v commands below work without any problems. This command I used in this answer to ensure, that on each Linux wherever the binaries are, they are found.

  5. Create the directory structure on RAM disk for the Google Chrome cache.

  6. It will only work if you have access, so make yourself an owner of the whole RAM disk.

  7. Since we can't know what might happen, it would be a good idea to remove possibly existing cache directory (symlink or real).

  8. Finally, let's create a symlink for the cache directory onto your RAM disk.

Note, that the solution below will create both:

  1. Normal Cache directory.

  2. In addition to the original solution, also the Media Cache directory, which will Chrome create upon loading some media.


The final script could look like this (should be portable):

#!/bin/sh

########################################################
##    Google Chrome                                   ##
##                               Cache on RAM disk    ##
########################################################

set -eu

# constants definitions for easy edits
username="vlastimil"
ramdisk_path="/ramdisk"
cache_path_ramdisk="${ramdisk_path}/google-chrome/Default"
cache_path_userdir="/home/${username}/.cache/google-chrome/Default"

# create directory structure on RAM disk
mkdir -p "${cache_path_ramdisk}"

# change ownership of RAM disk to my user
chown -R "${username}":"${username}" "${ramdisk_path}"

# remove possibly existing cache directory (symlink or real)
rm -r -f "${cache_path_userdir}"

# create symlink for cache directory onto RAM disk
ln -s "${cache_path_ramdisk}" "${cache_path_userdir}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .