DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

How To Create A RAM Disk On OS X

  • submit to reddit
        32768 = size in sectors (16MB in this case, a sector is 512 bytes)

$ hdid -nomount ram://32768
$ newfs_hfs /dev/disk1
$ mkdir /tmp/ramdisk1
$ mount -t hfs /dev/disk1 /tmp/ramdisk1

To unmount:

hdiutil detach /dev/disk1


Snippets Manager replied on Tue, 2008/06/17 - 6:55pm

a simple way There is a simpler way to create a ram disk described here: You can do in a single line.

Snippets Manager replied on Mon, 2007/04/23 - 7:32am

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