Created
October 14, 2010 19:52
-
-
Save Benabik/626901 to your computer and use it in GitHub Desktop.
OS X ramdisk script
This file contains hidden or 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
This file creates and mounts a ramdisk on OS X (10.5+, I believe) | |
Handy for setting up test environments. I use it for git like so: | |
device=`ramdisk 250 Git_Test` | |
export GIT_TEST_OPTS='--root=/Volumes/Git_Test' | |
make test | |
hdiutil detach $device |
This file contains hidden or 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/sh | |
program=`basename $0` | |
if [ $# -lt 1 -o $# -gt 2 ]; then | |
echo $? $# | |
echo "Usage: $program <size in MiB> [<disk name>]" | |
exit 1 | |
fi | |
size=$1 | |
name=$2 | |
[ "$name" ] || name=ramdisk | |
if [ -e "/Volumnes/$name" ]; then | |
echo "Disk named \"$name\" already mounted." | |
exit -1 | |
fi | |
size=$(($size * 2048)) | |
device=`hdiutil attach -nomount ram://$size` | |
status=$? | |
if [ $status != 0 ]; then | |
echo -n "$device" | |
exit $status | |
fi | |
device=`echo "$device" | tr -d '\n\t '` | |
diskutil=`diskutil erasevolume HFS+ "$name" "$device"` | |
status=$? | |
if [ $status != 0 ]; then | |
echo -n "$diskutil" | |
exit $status | |
fi | |
if ! [ -d "/Volumes/$name" ]; then | |
echo "Warning: \"/Volumes/$name\" not found. Ramdisk $device not mounted?" >&2 | |
fi | |
echo $device |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment