60

Does OS X (Snow Leopard in particular) have an equivalent to (some versions of) Linux's /dev/shm , ie something where you can write to and read from a file without necessarily touching the hard drive?

Terry N
  • 107
  • 1
  • 4
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

1 Answers1

60

You can create and mount a ram based disk as follows:

  1. Create a disk

    hdiutil attach -nomount ram://$((2 * 1024 * SIZE_IN_MB))
    

    hdiutil will return the name of the ramdisk.

  2. Format and mount the disk

    diskutil eraseVolume HFS+ RAMDisk NAME_OF_DISK
    
  3. Access the disk under /Volumes/<diskname>

    cd /Volumes/RAMDisk && touch testfile.txt && ls
    

Creating a 100MB ramdisk:

$ hdiutil attach -nomount ram://$((2 * 1024 * 100))
/dev/disk3

$ diskutil eraseVolume HFS+ RAMDisk /dev/disk3
Started erase on disk3
Unmounting disk
Erasing
Initialized /dev/rdisk3 as a 100 MB case-insensitive HFS Plus volume
Mounting disk
Finished erase on disk3 RAMDisk

Original source: http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/

ase
  • 13,231
  • 4
  • 34
  • 46
  • 12
    Broken links are one of the reasons why the StackOverflow community prefer full answers over links without any explanation. – Nupraptor Jun 15 '15 at 16:15
  • 12
    @Nupraptor: I updated the answer with a real answer. Thanks for bringing it to my attention! – ase Jul 24 '15 at 14:18