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.
It seems that Mountain Lion changes something… my ram disks which worked fine under Lion and earlier seem to be unmounting / lost when the system sleeps under Mountain Lion. I vaguely recall a similar problem occuring when I upgraded to Lion from Snow Leopard but I can’t recall that solution (although I’m sure I’m using in in a script in Lion which loses the ramdisk in ML.)
OOPS decimal out of place, the above line should read:
I ran Xbench.app pointing to my internal 7200 RPM disk and got a total disk score of 74.07.
Hence the RAM Disk score was 27X faster.
I have 4 GB of RAM, i created a RAM disk which claims to be 10 GB, ie. more than my RAM.
I ran Xbench.app pointing to my internal 7200 RPM disk and got a total disk score of 7407. I then ran Xbench.app and pointed to my ramdisk, and got a total disk score of 2041.
RAM Disk Test Total 2041.64
———————–Sequential 1288.62
—–Uncached Write 1055.33 647.96 MB/sec [4K blocks]
—–Uncached Write 3243.49 1835.16 MB/sec [256K blocks
—–Uncached Read 634.50 185.69 MB/sec [4K blocks]
—–Uncached Read 3674.15 1846.60 MB/sec [256K blocks]
———————–Random 4912.12
—-Uncached Write 1964.06 207.92 MB/sec [4K blocks]
—-Uncached Write 5929.19 1898.15 MB/sec [256K blocks]
—-Uncached Read 24386.08 172.81 MB/sec [4K blocks]
—-Uncached Read 10471.40 1943.04 MB/sec [256K blocks]
Internal 7200 Disk Test 74.07
Sequential 163.75
Uncached Write 172.35 105.82 MB/sec [4K blocks]
Uncached Write 163.45 92.48 MB/sec [256K blocks]
Uncached Read 131.50 38.48 MB/sec [4K blocks]
Uncached Read 203.98 102.52 MB/sec [256K blocks]
Random 47.86
Uncached Write 15.17 1.61 MB/sec [4K blocks]
Uncached Write 313.67 100.42 MB/sec [256K blocks]
Uncached Read 111.01 0.79 MB/sec [4K blocks]
Uncached Read 182.95 33.95 MB/sec [256K blocks]
Can someone help me run a minecraft server off of this created ram? I have 26.74 GB available, it says, and I would like to run a server off of this. Is it possible? Thanks!
[…] you want to quickly make a RAM disk for use on your Mac, you could create one manually through the command line, or you can make it even easier by downloading TmpDisk for Mac OS X. The […]
[…] 按照麦芽地一篇帖子中的方法,即可产生虚拟可存储介质来进行使用.也可参照OSXDaily的一篇文章来操作.但它在你重启机器後即消失,因此不可存储重要文件. […]
[…] See details here. […]
[…] Prevent SSD Wear by Using a RAM Disk Cache, MacOS X Hints (Jan. 4, 2011); see also OS X Daily, Create a RAM Disk in Mac OS X (Mar. 23, 2007); AppleWiki, RAM […]
[…] of favor. The utility I used on my Mac (and unwisely deleted) doesn’t seem to be available, but OS X Daily has simple instructions for Mac users. For Windows users I haven’t been able to find something […]
[…] 按照麦芽地一篇帖子中的方法,即可产生虚拟可存储介质来进行使用.也可参照OSXDaily的一篇文章来操作.但它在你重启机器後即消失,因此不可存储重要文件. […]
You may wish to see my earlier Safari post above.
I am not sure why a RAM disk appears to improve OS X speed. In theory OS X cache and VM control are so good that RAM disks are unable to increase speed. I did see one post which said RAM disks always use ‘wired’ memory but this fails to explain improvements when memory is little used.
I was able to increase Safari speed without a RAM disk by manually trashing all preferences, history and caches but not bookmarks. ‘Reset Safari’ did not reset all of these. Perhaps examining ALL iTunes files will resolve your issue. Probably best to backup before you start.
Any experience creating a RAM disk, specifically for helping iTunes run faster? I am on a 2006 Imac 21″ CoreDuo with 2GB RAM. Snow leopard latest. ITunes library is 500GB, so library file is 25MB and the library xml is 136MG. The genius lib file is 1.2GB.
Anyway, running alone, iTunes is sluggish giving the spinning wheel anytime I ask it to do anything that writes to or reads from disk the itunes Library file. So managing the collection, sorting names playlist creations and modification, all the daliy doings of my music maintenance involve this library file being accessed all the time. I think this is at the core of my sluggish iTunes. Mac OS activiity monitor shows free ram, and a modest 40GB virtual memory use. Even when other apps are involved, there is still free RAM. anyway, as soon as I ask itunes to do something in a new field, like go from scrolling artists to viewing the main list, and clicking sort all songs by date added..boom boom pow, i get the damned rainbow wheel.
Would a RAM disk help. Can I direct iTunes to use RAM disk scratch space, or perhaps create an applet that will pair with Itunes launching, create a RAM disk and create a fresh copy of the iTune library there, and keep it synced with the master library file there on the internal HD. Then tell iTunes to use this new RAM disk copy of the library file.
any thoughts or advice appreciated!
“diskutil erasevolume HFS+ “ramdisk” `hdiutil attach -nomount ram://1165430`” works fine for me on 10.6.2.
This doesn’t work with Snow Leopard. I’d like to have something that works with 10.6.2. As a scratch disk for Final Cut Express, a RAM disk would be great.
Created 10 GB RAM disk and I get up 1.1 GB/s write speeds, and 1 GB/s read speeds.
Now if I could get an SSD with these transfer rates, I’d be a happy camper :D.
Photoshop performance is improve significantly if you put your PS cache into RAM disk (and since I have 32 GB of RAM, and PS CS4 is still only 32 bit in OS X, I can create 20 GB RAM disk and still have plenty of RAM to run PS and lots of other apps).
Created 2 1GB RAM disks on my MacPro, hit 405MB/s transfer rate – This is a terrific idea for Photoshop, the GUI should be built into OS X.
http://www.youtube.com/watch?v=Cs2nZiZsVdA
[…] you’d rather not download anything, you can follow our command line instructions to create a ram disk in mac os x using no third party downloads or utilities, only the […]
Will ramdisk increase perfomance of webserver with mysql & php?
diskutil erasevolume HFS+ “ramdisks” `hdiutil attach -nomount ram://1165430`;
I used that to make a ram disk that is 500mb
Edit:
(or the 32 GB total) should read: (of the 32 GB total) in the above message.
Sorry. :)
I haven tried these scripts but I used “Espérance DV” mentioned in the first reply here. It’s great but it only allows 2 GB in size. :( I want 20 GB and then just keep 12 (or the 32 GB total) for apps and stuff. I benchmarked the Espérance DV RAM drive and the results can be seen here:
http://forums.macrumors.com/showpost.php?p=7838758&postcount=4
Enjoy.
I have just downloaded the free RAMDISK program .dmg file and it puts a ramdisk on the desktop which takes room from the internal hard disk so is it indeed a RAM disk? it does not seem so – therefore what is the point of it – a disk within the hard disk!?
I have just downloaded the free RAMDISK program .dmg file and it puts a ramdisk on the desktop which takes room from the internal hard disk so is it indeed a RAM disk? it does not seem so – therefore what is the point of it – a disk within the hard disk!?
Over here on OS X 10.5.6 (on intel mac mini 2,1) we receive the same error as mikey.
Unknown volume, that is unmountable.
$ hdiutil detach /dev/disk1
“disk1” unmounted.
hdiutil: couldn’t eject “disk1” – error 49168
$ df
Filesystem 512-blocks Used Available Capacity Mounted on
/dev/disk0s2 254341856 13817784 240012072 6% /
devfs 211 211 0 100% /dev
fdesc 2 2 0 100% /dev
map -hosts 0 0 0 100% /net
map auto_home 0 0 0 100% /home
/dev/disk1 2097152 24664 2072488 2% /private/tmp/ramdisk1
I tried these commands and fter a couple errors and guessing, I ended up with an unknown volume that I cannot access or delete!
df
Filesystem 512-blocks Used Avail Cap Mounted on
/dev/disk2 985 19 966 2% /private/tmp
hdiutil detach /dev/disk2
“disk2” unmounted.
hdiutil:couldn’t eject “disk2” – error 49168
Any thoughts?
thanks,
mikey
[…] Simple enough: […]
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.
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.
How do you change the size of the RAMdisk without using the script in bash shell.
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?
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.
I used a RAM disk with the first iMac and, if my memory is correct, with an earlier 7600 also.
The iMac saved RAM disk contents to disk automatically and could be booted from the RAM disk as mentioned elsewhere. It was practical to use both Disk First Aid and Norton Utilities while so booted even if the applications were too large to reside on the RAM disk.
I have a very old web page documenting speeding up Netscape with a RAM disk – http://links.open.ac.uk/www/ns.html
I have just demonstrated that a similar trick with Safari 5 on my 733 MHz G4 with OS X 10.5.8 also results in a speed improvement. This is what I did:
1 – Quit Safari.
2 – Used the terminal command from earlier here:
diskutil erasevolume HFS+ “ramdisk” `hdiutil attach -nomount ram://1165430`
3 – Via the Finder I dragged my Safari folder from /Users/neville/Library/Safari to the RAM disk and kept a backup copy elsewhere.
4 – Created a link via the terminal:
ln -s /Volumes/ramdisk/Safari /Users/neville/Library
5 – Restarted Safari.
Don’t forget to replace ‘neville’ with your user name and make sure that you backup your Safari file as the RAM disk will probably be lost when you shutdown or restart your Mac.
OS X has the facility to store RAM to disk automatically – portables do this to conserve battery and many other Macs can be modified also. I use it several times a day when I put my G4 desktop to sleep (details available if you can contact me!). I think that doing it during normal shutdown is possible but I cannot remember the details. Those interested could try ‘man pmset’ and ‘pmset -g’ in the terminal.
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?
1) If you are testing writing speed to/from the internal disk, you will not get speeds faster than what the DISK can do. You’re basically saying that “there’s no point to a formula 1 race track, because I brought my moped and I couldn’t go fast at all”
2) Even if you create a 100gig ram drive, no more ram will be allocated that the space actually used on the drive. If the space exceeds your physical ram, it goes to swap, and you’re back to physical disk.
3) Anything that uses some form of cache benefits from being on a ramdrive. If your physical disk is an SSD, it will live longer if you put anything that does tons of small writes on a ramdrive. Ramdrives are very useful, especially in these SSD & ram-for-free days.
[…] (thanks to this tutorial for how-to create a RAM disk in OS X) […]
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.
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
[…] Create a RAM Disk in Mac OS X – OS X Daily (tags: howto mac osx disk ram) […]
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.
@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
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.
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
what are the security implications for RAM disks?
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…
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