Create a RAM Disk in Mac OS X
Need to create an ultra-fast RAM disk in Mac OS X? We’ve got you covered with a command line trick that will generate a RAM disk of any size of your choosing. These instructions have been updated to support all versions of OS X, from modern releases to older ones too, so no matter what you’re running on the Mac, you’ll get a fast RAM disk running in no time at all.
Do keep in mind that RAM disks are temporary, and a reboot will cause the data on the RAM disk to clear off (just like RAM). Similarly, ejecting the RAM disk will remove it, and remove all data stored on the RAM disk. This makes RAM disks appropriate for temporary situations, caches, and situations where you need very fast disk read and write speeds.
How to Create a RAM Disk in Mac OS X 10.11, 10.8, 10.9, 10.10
From OS X El Capitan, Yosemite, Mountain Lion, OS X Mavericks, and presumably beyond, a simple ultra fast RAM disk can be made with the following command string:
diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://1165430`
That example will create a 600MB RAM disk, the number on the end is the size of the RAM disk.
To calculate the size of the RAM disk to make, or to generate your own, use the following formula:
Size of RAM disk desired * 2048 = amount to specify
Using the above example, that would be:
569*2048 = 1165430
You can always reverse this with division as well, math is fun eh:
1165430/2048 = 569
Simple enough formula, and that applies to generating RAM disks in all versions of OS X.
Here’s a 128MB RAM disk for example:
diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://262144`
I use a smaller RAM disk like that sometimes for cache files in OS X, it’s quite nice.
As usual with the command line, be sure to use proper syntax and to put commands onto a single line.
Create a RAM Disk in Mac OS X 10.5, 10.6, 10.7
These instructions are to create a RAM disk in OS X 10.5 Leopard, Snow Leopard, Lion, if you have troubles with the below commands for earlier version of Mac OS, try the following to create a 550mb RAM disk:
diskutil erasevolume HFS+ 'ramdisk' `hdiutil attach -nomount ram://1165430`
This has been tested and works in OS X 10.5.8, and 10.6.3, note that to remove the RAM disk you can simply eject it from the desktop as you would any other disk.
Create a RAM Disk in Mac OS X 10.4 and earlier
Earlier versions of OS X handle RAM disk creation a bit differently, but it’s still possible.
Here’s the original tip, sent in from one of our readers about creating an ultra-fast RAM disk in Mac OS X, as Stephen Adelson writes: “Back in Mac OS 9 and earlier you could make a RAM disk, a temporary disk that was super fast because it was read from system memory, or RAM, and not a relatively slow moving hard drive. In Mac OS X the feature has been removed from an easy GUI interface, but you can get the same effect and create your own RAM disk directly by typing the following commands in any terminal window.”
Let’s follow Stephen’s instructions below to create a RAM disk in Mac OS X:
Type the following exactly in the Terminal (the $ represents a bash prompt and is not to be typed):
$ hdid -nomount ram://52428800
$ newfs_hfs /dev/disk1
$ mkdir /tmp/ramdisk1
$ mount -t hfs /dev/disk1 /tmp/ramdisk1
to ditch the RAM disk and unmount it, just type
$ hdiutil detach /dev/disk1
Thanks Stephen for the great tip!
This has been updated to work with OS X Yosemite, OS X Mavericks, OS X Mountain Lion, Lion, Snow Leopard, Leopard, and Tiger. Basically, if it’s a Mac running a version of OS X, the above tricks will work for you to create a RAM disk.