Sponsors

Apple Store

Visit the official Apple Store to buy a Mac online. Free shipping!



Editors' Picks


Comments

Contact Us

Search

Top Posts

Categories

Recent Posts

Our Feeds


Create a RAM Disk in Mac OS X

Another great tip from one of our readers, 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.” Follow Stephen’s instructions below to create a 50mb RAM disk:

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!

Digg!


Social bookmarks:


Comments:

Comments: 17

Comment from Anon.
Time: March 23, 2007, 7:45 am

While creating a ram disk “by hand” as you’ve shown here is possible, you or your readers may be interested in a donation-ware System Preference Pane by Michaël Parrot called Espérance DV . For one, it uses a GUI. Also, it has a few useful features:

- save its contents in a dmg
- mount the ram disk on login
- move certain caches to the ram disk

Comment from Philip
Time: March 23, 2007, 8:13 am

Any idea if it’s possible to have the ramdisk *NOT* appear on the desktop? I don’t need to see it there, just want to have it…

Comment from anon the other
Time: March 24, 2007, 1:07 pm

what are the security implications for RAM disks?

Comment from hmills
Time: March 26, 2007, 2:33 pm

hey everyone might want to know that a RAM disk disapears on reboot as with the Data on it, so don’t expect to hold files there for a long time securely

Comment from C Dizzle
Time: March 29, 2007, 4:33 pm

Have you tried Esperance DV? It is a freeware app from the developer of ClawMenu that does the same thing, only it does it via it’s own System Preferences pane. I have used it with much success while encoding video files.

Comment from h3rbz
Time: April 23, 2007, 5:54 am

@original-post: http://snippets.dzone.com/posts/show/1808

Yo :)

I have thrown together a quick script for anybody that wants to create a ramdisk regularly. It’s flexible enough for me, but can be edited to offer more options (if u know a little .sh scripting). The disk is dynamicly named and will show up on the desktop when the script is finished. Unmounting can be done as any drive in the finder. The major differences between my and the above approach is that I use diskutil to mount the created drive, so Finder likes it better, and i give the volume a label, so it can be better recognized by the user …

Here it is:

Leila:~ samynew[14:30:55]$ cat ramdisk
#!/bin/bash
if [ -n “$2″ ]; then ARG_ERR=ERR; fi
if [ -z “$1″ ]; then ARG_ERR=ERR; fi
if [ -n “$ARG_ERR” ];
then
echo 1 argument: size in MB
exit
fi
MB_SIZE=$1
let “MB_SIZE *= 2048″
echo Creating ${MB_SIZE} 512-blocks ramdisk
CREATED_RAMDISK=`hdid -nomount ram://${MB_SIZE}`
echo New block device: ${CREATED_RAMDISK}
DISK_NAME=`basename ${CREATED_RAMDISK}`
echo Creating volume with label: ${DISK_NAME}
newfs_hfs -v ${DISK_NAME} /dev/r$CREATED_RAMDISK
echo Mounting in /Volumes/${DISK_NAME}
mkdir /Volumes/${DISK_NAME}
diskutil mount ${CREATED_RAMDISK}

Make sure it’s chmodded to be executable: chmod u+x ramdisk
Run as: ./ramdisk

I hope u like it.. :)

Grtz

H3rbz

Comment from D Lamblin
Time: May 1, 2007, 2:55 pm

Mac OS 9 (8 and starting with 7) had the awesome feature in Apple ROM that persisted your ramdisk between reboots. It was actually possible to format it; install OS 7 (minimal) onto a 16mb ram disk; select it as your start up disk, and reboot. rebooting would be crazy fast. then you could defrag your original volume or do backups or whatever. I still have a PowerMac 8500 that I can do this on.

Pingback from links for 2007-05-02 | Napolux.com
Time: May 2, 2007, 7:33 am

[…] Create a RAM Disk in Mac OS X - OS X Daily (tags: howto mac osx disk ram) […]

Comment from DD
Time: July 17, 2007, 5:28 pm

the following does not work in osx 10.4.9 on intel core 2 duo

$ 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

OS 8 was great!
Dave

Comment from Jeff Clark
Time: September 22, 2007, 4:52 pm

Two comments…
1. The size argument is calculated as MEGABYTES * 2048. So if you want a 256mb ram disk…. 256 * 2048 = 524288
2. Under 10.4.8+ use the hdik tool to allocate the ram device….
hdik -nomount ram://524288

Rest of the commands will be the same.

Pingback from How to use a RAM / memory disk for MySQL in Rails at JJB Blog
Time: September 29, 2007, 1:58 pm

[…] (thanks to this tutorial for how-to create a RAM disk in OS X) […]

Comment from NVR
Time: October 14, 2007, 1:02 am

Well… I see two problems with the RAMdisk:

1) I tested it - it clocked in at 51 MBps from/to internal HD in my MBP C2D. This is lower than what I got when using a FW800 HD (57 MBps). The internal HD (7200 RPM) might not be able to deliver more than 50-60 MBps anyway. So - there is really no big deal in actually using a RAM-disk. Has it occurred to you that there might be a reason there’s no RAM-disk easily available in Mac OS X? Maybe it’s because there’s no point! Back in the days when harddisks were slumbering around 1-5 MBps, a RAMdisk would really speed up the computer. OK - I didn’t test multiple rapid transactions - it’ll probably outclass any harddisk in terms of seektime, etc. Good for databases?

2) I couldn’t help noticing that MenuMeters didn’t catch the fact that my RAM use increased by 1 GB! So - unless this is a bug with MenuMeters, the computer is unaware that this space is occupied! This sounds like a potential for disaster.

Any thoughts and reflections on this observation, anyone? Are RAM-disks really that useful?

Comment from ALC
Time: October 15, 2007, 4:02 pm

It was possible under Windows to create a Ramdisk and then set the Web browser to write temp files to it. This increased the snappiness of the browser considerably.
I wouldn’t mind doing this with Safari, but see no way to tell it where to put the temp files…. in the same way that everyone says that OS X disks don’t need to be defragged, everyone says that Ramdisks are unnecessary. I would love to know if this is the case.

Comment from ohbogus
Time: October 22, 2007, 2:32 pm

i use two 2GB RAM-disks in my G5 dual 2Ghz which is equipped with 8GB of RAM, and a few internal 160 and 250 GB disks.

when instructing photoshop to use these two ramdisks as primary scratch disks, the performance is improved significantly, mainly when saving large files (>500MB). the time photoshop needs to “prepare for saving” is reduced by about 80%.

i figure this is because photoshop needs to reshuffle the scratch data from all the fragmented places on the scratch disks in order to correctly write these large files. this seems to be alot faster on a RAM disk.

any comments?

Comment from Sharath
Time: October 23, 2007, 6:38 am

How do you change the size of the RAMdisk without using the script in bash shell.

Comment from rdlfo
Time: November 20, 2007, 8:21 pm

On a intelcore2duo mac running 10.4.10:

I tested the tip, but the only way to ’see’ the ram disk (on the desktop, and photoshop’s preference pane for scratch disk) was logging out after creating it and then logging in again. Then, for ‘erasing’ i have to reboot. I’ve also tried the hdik tool but it only work as root so, as user, a you don’t have write permissions on the created volume.

Any thoughts?

Best regards.

Comment from seff
Time: June 17, 2008, 4:54 pm

a simple way

There is a simpler way to create a ram disk described here:
http://mac.wikia.com/wiki/RAM_disk#Creating_a_RAM_disk
You can do in a single line.

Write a comment





March 23rd, 2007