How to make a RAM disk larger than 2 GiB
UPDATE 2009-09-23: This procedure is no longer necessary since Snow Leopard.
The most frequent question I get about Make RAM Disk is “How do I create a RAM disk larger than 2 GiB?”.
Make RAM Disk uses Mac OS X’s disk images system to do its work. Unfortunately, as of Leopard, the command to create a single RAM disk refuses to create one that is larger than 2 GiB in size, even if you have the RAM to do it.
However, there is a solution.
Jennek Geels, a user who asked the aforementioned question, worked with Jean-Sébastien Rousseau to figure out a solution using Mac OS X’s software-RAID feature. Here’s a refined version of their solution:
- dev1=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
- Repeat step 1 as many times as necessary, changing the variable number each time (dev1, dev2, dev3, and so on).
- diskutil createraid stripe $VOLUMENAME HFS+ $dev1 $dev2 .. $devN
So, for example, to create an 8 GiB RAM disk:
- NUMSECTORS=4194304
- dev1=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
- dev2=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
- dev3=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
- dev4=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
- diskutil createRAID stripe $VOLUMENAME HFS+ $dev1 $dev2 $dev3 $dev4
diskutil createRAID will format and mount the RAID device automatically; you don’t need to run newfs_hfs and diskutil mount like you do when creating a single-device RAM disk.
I tested the speed briefly (just one run each, not averaged over several runs). Copying 2,000 MiB from /dev/zero to an 8 GiB RAIDed RAM disk was about one second faster (~5 seconds) than copying it to a 2 GiB single RAM disk (~6 seconds). Your results may vary.
When you’re done, you’ll need to eject all of the devices separately, starting with the RAID:
- diskutil eject $RAIDDEVICE
- hdiutil detach $dev1
- hdiutil detach $dev2
- ..
- hdiutil detach $devN
If you don’t remember the device name of the RAID device, you can look it up in the output of diskutil listRAID. Look for the line labeled “Device Node:”.
I have no immediate plans to add this RAID feature to Make RAM Disk, because I’d also need to write an app to handle the full clean-up procedure. For now, if you really need a RAM disk that big, you can probably handle creating it and tearing it down yourself.