Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create a RAM disk for using with XCode
# Create a RAM disk with same perms as mountpoint
# Script based on with some additions
# Usage: sudo ./ start
DEV_IPHONE_DIR="/Users/$USERNAME/Library/Application Support/iPhone Simulator"
RAMDisk() {
echo "Creating RamFS for $mntpt $rdsize"
# Create the RAM disk.
dev=`hdik -drivekey system-image=yes -nomount ram://$rdsize`
# Successfull creation...
if [ $? -eq 0 ] ; then
# Create HFS on the RAM volume.
newfs_hfs $dev
# Store permissions from old mount point.
eval `/usr/bin/stat -s "$mntpt"`
# Mount the RAM disk to the target mount point.
mount -t hfs -o union -o nobrowse -o nodev -o noatime $dev "$mntpt"
# Restore permissions like they were on old volume.
chown $st_uid:$st_gid "$mntpt"
chmod $st_mode "$mntpt"
# Test for arguments.
if [ -z $1 ]; then
echo "Usage: $0 [start|stop|restart] "
exit 1
# Source the common setup functions for startup scripts
test -r /etc/rc.common || exit 1
. /etc/rc.common
StartService () {
ConsoleMessage "Starting RamFS disks..."
RAMDisk "$TMP_DIR" 128
RAMDisk "$RUN_DIR" 64
#RAMDisk /var/db 1024
#mkdir -m 1777 /var/db/mds
StopService () {
ConsoleMessage "Stopping RamFS disks, nothing will be done here..."
# diskutil unmount /private/tmp /private/var/run
# diskutil unmount /private/var/run
RestartService () {
ConsoleMessage "Restarting RamFS disks, nothing will be done here..."
RunService "$1"
Copy link

brunogama commented Feb 17, 2014

does this work in OSX mavericks? nothing seens to happen when I execute this script. There's nothing mounted in finder.

Copy link

yas375 commented Feb 17, 2014

@brunogama I'm not sure if you should see disks in Finder...You could list them using df command:

~  df -h
Filesystem      Size   Used  Avail Capacity  iused    ifree %iused  Mounted on
/dev/disk1     233Gi  112Gi  121Gi    49% 29395581 31591938   48%   /
devfs          198Ki  198Ki    0Bi   100%      685        0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%        0        0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%        0        0  100%   /home
/dev/disk3     128Mi  3.0Mi  125Mi     3%      777    31989    2%   /private/tmp
/dev/disk4      64Mi  1.5Mi   62Mi     3%      385    15997    2%   /private/var/run
/dev/disk5      64Mi  1.5Mi   62Mi     3%      385    15997    2%   /Library/Caches
/dev/disk6     1.0Gi   15Mi  1.0Gi     2%     3805   258337    1%   /Users/yas/Library/Caches
/dev/disk7     1.0Gi   12Mi  1.0Gi     2%     3080   259062    1%   /Users/yas/Library/Developer/Xcode/DerivedData
/dev/disk8     1.0Gi   12Mi  1.0Gi     2%     3080   259062    1%   /Users/yas/Library/Application Support/iPhone Simulator

Copy link

kevinchiu commented Apr 5, 2014

How to do you stop everything? When I try unmount, I get:

kevin$ diskutil unmount /private/tmp 
Volume (null) on disk3 failed to unmount

Copy link

viktoricalonia commented Nov 13, 2014

is delete version of this available?? can i have the link?? thanks ahead

Copy link

derjohng commented Apr 7, 2015

I have rewrote this as a new version that can unmount the disks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment