Fastest way to create ramdisk in Ubuntu/Linux

Welcome to Linux Screw! If you're new here, you may want to subscribe our RSS feed.

I hope many of you will agree that sometimes it’s really good idea to have some small amount of RAM mounted as a filesystem. It may be necessary when running some bash or perl script that handles, say, thousands of small files so it’s much more effective not to waste computer resources on reading/writing data on hard disk but keep those files directly in memory. This idea is known as Virtual RAM Drive or ramdisk and can be setup in Ubuntu or almost any other Linux distribution using the following commands under root (to become root in Ubuntu use "sudo -s“):

# mkdir /tmp/ramdisk; chmod 777 /tmp/ramdisk
# mount -t tmpfs -o size=256M tmpfs /tmp/ramdisk/

where 256M is amount of RAM you wish to allocate for ramdisk. It’s clear that this value should be less than amount of free memory (use “free -m“). BTW, if you specify too many MBs for ramdisk Linux will try to allocate it from RAM and then from swap so resulting performance would be very poor.

 
 
» You might also be interested in the following articles:
FAQ: How to select fastest APT server in Debian
The fastest way to disable PC speaker in Ubuntu
Download or Upgrade Ubuntu at highest speed
Make linux shell scripts encrypted
Create Linux user with password



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!

6 Responses to “Fastest way to create ramdisk in Ubuntu/Linux”


  1. 1 GhostOrchid

    1# mkdir /tmp/ramdisk; chmod 777 /tmp/ramdisk
    2# mount -t tmpfs -o size=256M tmpfs /mnt/tmpfs/

    what is the purpose of line 1, if we mount ramdisk on /mnt/tmpfs on line 2?

  2. 2 artiomix

    Thanks, GhostOrchid — I fixed the typo.

  3. 3 Todd Lyons

    Ubuntu by default already has /dev/shm mounted as tmpfs. If you really like the name /tmp/ramdisk, you can just do:
    1# ln -s /dev/shm/ /tmp/ramdisk

    If the name isn’t all that important to you, just use /dev/shm directly.

  4. 4 Dave

    This is a seriously handy tip if you are using an SSD drive and wish to minimise the read / write access during heavy scripts.. Top! :)

  5. 5 tommy

    why would there be ram0 -ram15 in /dev why would you need to make more how do you edit these?

  1. 1 Links 25/3/2010: Free Software Award Winners, Red Hat’s Results Analysed | Boycott Novell

Leave a Reply




Friendly Sites:Who is behind Linux Screw?
GeekyBits³ | Bash Cures Cancer | OMG! Ubuntu!
My SysAd Blog | Web Upd8
ZEPY | Linux config Wiki | Planet Sysadmin
a non-geek's linux notes | Linux Today
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem N. (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››