Skip to content

Instantly share code, notes, and snippets.

@ben181231
Created February 25, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben181231/820ed7533bee9c21f7b3 to your computer and use it in GitHub Desktop.
Save ben181231/820ed7533bee9c21f7b3 to your computer and use it in GitHub Desktop.
Create ram disk on OS X
#!/bin/bash
LIMIT=8 #size limit
if [[ $# -eq 1 ]]; then
if [[ ! $1 =~ ^[0-9]+$ ]]; then
>&2 echo "Error: Invalid parameter: \"$1\""
exit 1
fi
SIZE=$1
elif [[ $# -eq 0 ]]; then
SIZE=1
else
>&2 echo "Error: Too many parameters"
exit 2
fi
if [[ $SIZE -gt $LIMIT ]]; then
>&2 echo "Error: Should not allocate more than ${LIMIT} GB"
exit 3
fi
if [[ ! -e /Volumes/RamDisk ]]; then
echo "Allocating ${SIZE} GB of Ram Disk..."
diskutil erasevolume HFS+ RamDisk `hdiutil attach -nomount ram://$((1000*1000*2*$SIZE))`
else
>&2 echo "Error: Ram Disk is exsiting"
exit 4
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment