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.

Beginners to the different linux kernels will find this article outlining the different versions of linux at Businesswebhostingplans.com very useful.

 

30 Comments

 

  1. March 24, 2010  1:07 pm by GhostOrchid Reply

    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. March 24, 2010  1:21 pm by artiomix Reply

    Thanks, GhostOrchid -- I fixed the typo.

  3. March 25, 2010  3:50 pm by Todd Lyons Reply

    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. Pingback : Links 25/3/2010: Free Software Award Winners, Red Hat’s Results Analysed | Boycott Novell

  5. April 26, 2010  10:18 pm by Dave Reply

    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! :)

  6. July 10, 2010  3:12 am by tommy Reply

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

  7. December 31, 2010  10:14 pm by license plate frames Reply

    Any opportunity you could suggest a good feed reader? I wish to follow your website to keep up with what you write.

  8. January 11, 2011  8:53 am by GeorgeP Reply

    Thanks for a handy tip! You saved my ass!

  9. January 21, 2011  4:55 pm by liver2 Reply

    I am noöbe at linux commands..can someone put a correct code as trying to execute line 1&2 gives error. also, I have 4GB RAM, so how can I use most of (or atleast 1GB) for ramdisk? Thanks all.

  10. Pingback : Usage of a Ramdisk on Linux » Philipp Klaus's Blog

  11. January 26, 2011  8:25 pm by Vincent Reply

    @liver2

    Maybe it is only because you don't have the permissions to make a directory, just type 'sudo' at the beginning of each line and enter the password required.

  12. Pingback : Create a ramdisk | INDLOVU

  13. February 6, 2011  4:21 am by Shannon Perrigo Reply

    F*ckin’ awesome things here. I’m very glad to see your article. Thanks so much and i'm taking a look ahead to touch you. Will you kindly drop me a mail?

  14. February 12, 2011  3:40 pm by Anna Reply

    I think this is one of the most significant info for me. And i am glad reading your article. But want to remark on few general things, The website style is great, the articles is really great : D. Good job, cheers

  15. February 18, 2011  7:27 am by web hosting delhi Reply

    Strange this post is totaly unrelated to what I was looking google for, nevertheless it used to be listed at the first page. I assume your doing something right if Google likes you sufficient to put you at the first web page of a non similar search.

  16. Pingback : Centos5 Ramdisk help

  17. April 8, 2011  9:23 pm by David Houghton Reply

    I look at this and want to do it. One thing, I have no idea where you type this. Lots of instructions, but where do I type these instructions exactly. Many thanks.

  18. May 13, 2011  8:32 am by smallqna Reply

    system are that it gives you everything you need; you only need to present the lessons to your child.

  19. May 14, 2011  9:54 pm by Tim Rohde Reply

    smallqna - You type it in your shell using Terminal. On Ubuntu systems its here:
    Applications (int the top left corner of task bar by default) => Accessories => Terminal.

  20. April 2, 2012  12:05 pm by root Reply

    Nice.. work
    My question.. howto get the ramdisk to be made at boot-Up

    • April 2, 2012  3:24 pm by Artem Nosulchik Reply

      You can create the script containing those ramdisk commands and then add it to startup according to this setup: http://www.ubuntuka.com/autostart-ubuntu-startup/

    • February 4, 2013  11:59 pm by Robert Reply

      You can define Your ramdisk to fstab:
      #######
      tmpfs /mnt/ramdisk tmpfs size=8m,auto,rw,users 0 0
      #######
      (of course You can ommit rw and users mount options and change size paramter according to Your needs).

  21. April 30, 2012  5:55 pm by SEM Reply

    Your article is rocking and knowledgeable I truly appreciate the way you write . I would like to read more from you.

  22. June 22, 2012  9:53 am by satish Reply

    I see these files in /dev/shm. They are modified everyday. What are these?
    pulse-shm-1187254147 pulse-shm-3643037261 pulse-shm-726713703
    pulse-shm-1327229993 pulse-shm-3776639608
    pulse-shm-3419994561 pulse-shm-46789500 each one is 67.1mb. Opened them with Leafpad and Wordpad but could see nothing. Empty. How can I delete them?

  23. August 9, 2012  1:01 am by LoadingDose Reply

    I would like to use mdadm to create a RAID1 array (mirror) with two components:
    - a regular block (disk) device, --write-mostly
    - a RAM-disk

    My system has oodles of RAM. So the idea is to put frequently used executables on this array, so that:
    - they are speedily retreived from RAM;
    - changes are persistent

    Questions:
    - is this a crazy idea?
    - If not, how do I create the required block RAM device, one that mdadm will accept?

    • October 29, 2012  3:20 pm by Juanjo Reply

      Have you tried to export a directory using iscsi and connect to it from the same machine? It's hard but I think it could be the way

  24. Pingback : Quickies: instant ramdisk « 0ddn1x: tricks with *nix

  25. Pingback : Flash slow in Windows or Linux? There maybe a fix. «

Leave a reply

 

Your email address will not be published.