Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created March 10, 2015 02:28
Show Gist options
  • Save jsfaint/cbe9611605aaac8453ef to your computer and use it in GitHub Desktop.
Save jsfaint/cbe9611605aaac8453ef to your computer and use it in GitHub Desktop.
Create RAM Disk for OS X
#!/bin/bash
size=1024
usage() {
echo "$0: Create RAM Disk with given size(default is 1024MB)"
echo " e.g.: $0 512"
exit 1
}
if [[ $# -eq 1 ]]; then
size=$1
re='^[0-9]*$'
[[ ! $size =~ $re ]] && usage $0
else
usage $0
fi
sector=`echo "$size * 4 * 512" | bc`
echo "Create ${size}MB RAM Disk"
diskutil erasevolume HFS+ 'RAMDisk' `hdiutil attach -nomount ram://$sector`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment