How to add a ramdisk to the eeePC

This page describes how to add a ram disk to your system. Very useful if you have movies on an external hdd that you want to watch from RAM (if you have 2 gigs of memory) instead of keeping the external media switched on!

The ramdisk is implemented as a tmpfs filesystem, and will grow as you copy things to it (and shrink when things are removed).

#!/bin/bash
#-----------------------------------------------------------------------------
# Name        : mkramdisk
# Author      : Jon Bradbury
# Description : Mount a ramdisk in your home directory in a subdirectory
#               called ramdisk if one doesn't already exist.
#-----------------------------------------------------------------------------

#--- Is there a file called ramdisk?
if [ -e ~/ramdisk ]; then

  #--- Is it a directory?
  if [ ! -d ~/ramdisk ]; then

    #--- No, so we cannot proceed
    echo "There's already a file called ramdisk in your home directory"
    exit 1

  fi

else

  #--- No file or directory, so we're free to create one
  mkdir ~/ramdisk

fi

#--- Mount it if it's not already mounted
mount | grep -q ~/ramdisk
rez=$?
if [ $rez = 1 ]; then
  sudo mount -t tmpfs tmpfs ~/ramdisk
fi

#-----------------------------------------------------------------------------
# EOF
#-----------------------------------------------------------------------------

Then, to install it, type this in a console (Ctrl-Alt-t) JUST ONCE :

sudo -s
chmod +x mkramdisk
mv mkramdisk /usr/local/bin/
echo >> /usr/bin/startsimple.sh
echo "/usr/local/bin/mkramdisk"  >> /usr/bin/startsimple.sh
echo >> /usr/bin/startfull.sh
echo "/usr/local/bin/mkramdisk"  >> /usr/bin/startfull.sh
/usr/local/bin/mkramdisk

Explaination :

You now get a directory called “ramdisk” in your /home/user/ directory (if you open eeeXandros' file manager, the folder “ramdisk” should be visible under “My Home”).

Be aware that the data in this directory is volatile and everything that is in it will be lost when rebooting.

The script will exit with a message if there is a normal file (ie, not a directory/folder) in your home directory called “ramdisk”.

Credits

Jon Bradbury (research, script)

eFfeM, Sangorys (article)

Dec 2007 last update : 11 April 2008