# Run chromium in a RAMDISK, avoid excessive disk (SSD) writes

## devsk

I just wrote this script for myself and thought I would share it with you folks if you want to run chrome in a ramdisk, just like some folks did with firefox.

Chrome is fast. Loads my 3 windows full of 36 tabs in under two seconds. The rsync used by the script is really fast too. You need to install xdialog. I have made the browser a loop because I was seeing a lot of memory leaks, so I was just thinking about recycling the browser once in a while. It syncs with disk on exit or crash or a kill. Fairly small and straightforward. Have a look! And Enjoy!

```
#!/bin/sh 

# 

# Following one time activities need to happen: 

# 1. To be able to use this script, you need to add the following line in /etc/fstab 

# chromium /home/memyself/.config/chromium tmpfs size=192M,noauto,user,exec,uid=1001,gid=100 0 0 

# 

# 2. touch /home/memyself/.config/chromium/.unpacked 

# 

# 3. mv /home/memyself/.config/chromium /home/memyself/.config/chromium.ondisk && mkdir /home/memyself/.config/chromium

# 

# Do the above ONLY the first time. 

function got_hup() 

{ 

        grep -q /home/memyself/.config/chromium /etc/mtab 

        if [ $? -eq 0 ] 

        then 

                # it was mounted and unpacked 

                if [ -f /home/memyself/.config/chromium/.unpacked ] 

                then 

                        echo "Mounted and used data, syncing it back..." 

                        rsync --delete-excluded --delete  -H -av -x \ 

                                --exclude=/home/memyself/.config/chromium/rsync.log \ 

                                --exclude=/home/memyself/.config/chromium.ondisk/rsync.log \ 

                                /home/memyself/.config/chromium/ \ 

                                /home/memyself/.config/chromium.ondisk/ \ 

                        > /home/memyself/.config/chromium.ondisk/rsync.log 2>&1 

                fi 

        fi 

        exit 0 

} 

# trap these and rsync back to disk 

trap got_hup 1 2 3 6 15 

# mount and unpack 

grep -q /home/memyself/.config/chromium /etc/mtab 

if [ $? -ne 0 ] 

then 

        echo "Not mounted, mounting now..." 

        mount /home/memyself/.config/chromium 

fi 

# unpack the stuff if not already there 

if [ ! -f /home/memyself/.config/chromium/.unpacked ] 

then 

        echo "Not unpacked, unpacking from ondisk now..." 

        rsync --delete-excluded --delete  -H -av -x \ 

                --exclude=/home/memyself/.config/chromium/rsync.log \ 

                --exclude=/home/memyself/.config/chromium.ondisk/rsync.log \ 

                /home/memyself/.config/chromium.ondisk/ \ 

                /home/memyself/.config/chromium/ \ 

        > /home/memyself/.config/chromium/rsync.log 2>&1 

fi 

# go into a loop 

while true 

do 

        #chromium-bin --single-process "$@" & 

        #chromium-bin --process-per-tab "$@" & 

        echo "Starting the browser..." 

        chromium-bin --process-per-site "$@" 

        Xdialog --yesno "Exit the browser?" 8 40 

        if [ $? -eq 0 ] 

        then 

                got_hup 

        fi 

done
```

Last edited by devsk on Sat Jan 02, 2010 7:21 pm; edited 1 time in total

----------

## shazow

 *Quote:*   

> # 2. touch /home/memyself/.config/.unpacked

 

Shouldn't this be /home/memyself/.config/chromium/.unpacked or somesuch?

Also, I already run /tmp on tmpfs, would it make sense to do something like this to use /tmp and sync back to ~/.config, without messing up my existing ~/.config?

- shazow

----------

## devsk

 *shazow wrote:*   

>  *Quote:*   # 2. touch /home/memyself/.config/.unpacked 
> 
> Shouldn't this be /home/memyself/.config/chromium/.unpacked or somesuch?
> 
> Also, I already run /tmp on tmpfs, would it make sense to do something like this to use /tmp and sync back to ~/.config, without messing up my existing ~/.config?
> ...

 Corrected. Sorry, for missing chromium in the path.

Actually, I never meant to mess up ~/.config. I wanted to affect only ~/.config/chromium. The script did the right thing but the comments which instructed the three manual steps were wrong as you pointed out.

As for putting stuff in /tmp and syncing it from there, you can definitely do that, it will only require minor modifications to the script. I don't use /tmp on tmpfs, so I created a separate one for chromium. Its actually better and cleaner if its separate from /tmp. You can unmount it without bothering the rest of the system e.g.

Thanks for catching the bug.

----------

## shazow

Chrome aside, I would recommend using tmpfs for /tmp. Pretty ideal, especially if you're worried about needless SSD thrashing.

My fstab entry:

```
none  /tmp  tmpfs  size=256m  0 0
```

I imagine it's more elegant to re-use /tmp just because every other app already does, and this way I don't need to mount a separate partition for each app I want to load into RAM. I could see unifying this script to work with pretty much any app.

Anyways, I'm working on a mod of the script to use /tmp, where it symlinks it into /tmp instead of mounting. I'll post it here once I rid all the bugs.  :Smile: 

- shazow

----------

## shgadwa

Where does this script go? In what folder?

----------

## devsk

 *belikeyeshua wrote:*   

> Where does this script go? In what folder?

 I named mychromium and put it in ~/bin after chmod +x on it. Note that you need the path where you put it in PATH env var. You can just copy it in /usr/bin.

----------

## shgadwa

 *devsk wrote:*   

>  *belikeyeshua wrote:*   Where does this script go? In what folder? I named mychromium and put it in ~/bin after chmod +x on it. Note that you need the path where you put it in PATH env var. You can just copy it in /usr/bin.

 

Ok, thanks that sounds easy enough. One thing that I'm unsure about is... what do you mean by PATH env var? I thought you were talking about the script here, but that can't be it because there is no env var in your script.

----------

## devsk

 *belikeyeshua wrote:*   

>  *devsk wrote:*    *belikeyeshua wrote:*   Where does this script go? In what folder? I named mychromium and put it in ~/bin after chmod +x on it. Note that you need the path where you put it in PATH env var. You can just copy it in /usr/bin. 
> 
> Ok, thanks that sounds easy enough. One thing that I'm unsure about is... what do you mean by PATH env var? I thought you were talking about the script here, but that can't be it because there is no env var in your script.

 You have some work to do to get familiar with how Unix works. PATH is the environment variable which determines how to find the program you are trying to run. It usually has /usr/bin and /bin in it, so any program you put in the directory /usr/bin will be directly callable, without full path. You do "echo $PATH" in a shell to see what the path value is.

----------

## shgadwa

Well, I replaced all the memyself's with my user name and I did chmod +x on the file and moved it to /usr/bin. I did everything that the script said to do.

But, when I try to start it, I get this:

```
shawn@atlantis ~ $ chromium-bin

[3018:3018:122915575:FATAL:/b/slave/chromium-rel-linux/build/src/chrome/browser/browser_main.cc(655)] Check failed: profile. Cannot get default profile.

Trace/breakpoint trap

```

Thank you for the help.

EDIT: It looks like I have a problem with the PATH. Funny, I've been using Linux for about 3 years now, and gentoo for over a year... and I don't really know about $PATH and things like that.

I did execute the script by clicking on it, and that opens up chromium. Its a lot faster!  :Wink: 

Also, I'm thinking... this has improved the speed of our satellite internet so much that I would like to set this up in our windows XP computers and our Mac OS X computers. Is that possible?

----------

## desultory

 *devsk wrote:*   

> You can just copy it in /usr/bin.

 Better yet, /usr/local/bin/.

----------

## V10lator

 *shazow wrote:*   

> Anyways, I'm working on a mod of the script to use /tmp, where it symlinks it into /tmp instead of mounting. I'll post it here once I rid all the bugs. 

 

Why symlinking? Why don't you simple change

chromium /home/memyself/.config/chromium tmpfs size=192M,noauto,user,exec,uid=1001,gid=100 0 0

to

/tmp/chrom-speedup /home/memyself/.config/chromium tmpfs user,exec,bind 0 0

or something like that? Of course the dir /tmp/chrom-speedup has to exist. The mount commands in the script should work with that, too  :Wink: 

----------

## mrmarcdee

When I set this up all of my configuration seems to be lost. So I reconfigured it, and then the next time I rebooted and restarted chromium the configuration was gone again. Whats going on? Does it not save configuration to the harddrive because it is running in RAM or what? Can this be fixed?

Thanks.

----------

## equilibrium

what about using /tmp (if you already have it) ?

```
#!/bin/bash

STATIC=chrome

LINK=chromium

PROFILE=/tmp/$USER/chromium

cd ~/.config/

[[ -r $PROFILE ]] || install -dm700 $PROFILE

if [[ `readlink $LINK` != $PROFILE ]]; then

  mv $LINK $STATIC

  ln -s $PROFILE $LINK

fi

if [[ -e $LINK/.unpacked ]]; then

  rsync -av --delete --exclude .unpacked ./$LINK/ ./$STATIC/

else

  rsync -av ./$STATIC/ ./$LINK/

  touch $LINK/.unpacked

fi
```

then just setup this script in crontab or on bash_login/logout

```
echo '/location/of/script' | tee -a ~/.bash_logout ~/.bash_login >/dev/null
```

crontab -e

```
# sync google chromium profile to ramdisk on /tmp

0 */1 * * * /usr/local/bin/chrome-sync &> /tmp/chrome-sync.log
```

----------

