Using RAM Drives

After getting a new Macbook Pro with 16GB of RAM (G.Skill, not from Apple, highly recommended), I starting looking for ways to put it to use. One of my favorite hacks is mounting a virtual disk with a portion of the RAM. Once you create a RAM drive, you can take advantage of the theoretical 10GB/s read/write speed to RAM. Everything stored in the RAM is temporary and will disappear on unmount or reboot.

It’s pretty simple to do, just run this command in the Terminal:

$ diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://4194304`

The number at the end of the command is the number of 512 byte sectors for the disk. For a 2GB disk: 2GB = 2147483648 bytes. 2147483648 / 512 = 4194304 disk sectors.

You’ll need to run the command every time you restart the computer. So drop it in an Automator app and add it to your Startup Items.

One great use for a RAM drive is to use it as Photoshop’s scratch disk. I played with the size a little and found the sweet spot to be around 4GB, which might be a little big if you have 8GB of RAM instead of 16GB.

Other cool things you can do with a very fast, but temporary disk:

  • Store a working copy of large files for instant access
  • Run portable apps entirely in the memory
  • Get a small linux distro like Puppy Linux and running it from a VM. Entire operating system in memory.

If you’re running an SSD, you can get even more benefits out of storing stuff in memory. Set your log files to write to the SSD, along with anything else that writes to the drive frequently. This reduces the number of writes to the SSD and boosts the longevity of your drive.

Have another cool use for a RAM drive? Comment below or tweet me @nathancahill.