Why do Mac OS X ramdisks appear to be limited to 550mb and how can I change this?

All I can find on the Internet is a one line bash command to activate a ramdisk. It is only 550mb and I would like to be able to create on with more space? Is there a way to configure how big they can be? If not, why are they limited in the first place?


Here is the one-liner I found to create a ramdisk:

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

It is actually two commands; if you run them individually, you get:

$ hdiutil attach -nomount ram://1165430
/dev/disk4              

$ diskutil erasevolume HFS+ "ramdisk" /dev/disk4
Started erase on disk4
Unmounting disk
Erasing
Initialized /dev/rdisk4 as a 569 MB HFS Plus volume
Mounting disk
Finished erase on disk4 ramdisk

The first command creates a block storage device in RAM, and the second command formats it with the standard OS X filesystem.

If you run df to see how much free space is on your disks, you'll get:

$ df
Filesystem                        512-blocks      Used Available Capacity  Mounted on
/dev/disk0s2                       974509344 435640768 538356576    45%    /
....
/dev/disk4                           1165424     27376   1138048     3%    /Volumes/ramdisk

Note how it shows that the RAM Disk is using 1165424 '512-blocks' (which, if you run df -h, for human readable output, you'll see is '569 Mi').

So, the answer is, change the number you specify in the first command, which specified how large the disk is in 512 byte blocks. If you want 1.5 GB (or, perhaps I should say 'GiB', go as follows:

           1024 MiB   1024 KiB   1024 bytes    1 block  
 1.5 GiB * -------- * -------- * ---------- * ---------   = 3145728 blocks                                                                 
             GiB        MiB         KiB       512 bytes                                         

To verify, I'll run the following commands:

$ hdiutil eject /Volumes/ramdisk/

$ diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://3145728`
Started erase on disk4
Unmounting disk
Erasing
Initialized /dev/rdisk4 as a 2 GB HFS Plus volume
Mounting disk
Finished erase on disk4 ramdisk

$ df
Filesystem                        512-blocks      Used Available Capacity  Mounted on
/dev/disk0s2                       974509344 435460472 538536872    45%    /
...
/dev/disk4                           3145728     24696   3121032     1%    /Volumes/ramdisk

$ df -h 
Filesystem                          Size   Used  Avail Capacity  Mounted on
/dev/disk4                         1.5Gi   12Mi  1.5Gi     1%    /Volumes/ramdisk

It sounds like previously you could only create a RAM disk up to 2.1 GiB, but that is not the case in Snow Leopard and newer.

Also, there are tools to help create RAM disks without calculating blocks yourself. I haven't used them, but here are three: TmpDisk, Make Ram Disk, and crd.