Created
February 25, 2015 15:32
-
-
Save ben181231/820ed7533bee9c21f7b3 to your computer and use it in GitHub Desktop.
Create ram disk on OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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