Skip to content

Instantly share code, notes, and snippets.

@cisoun
Last active November 2, 2021 14:06
Show Gist options
  • Save cisoun/3debd1376dc261585af829bb07b7b4b8 to your computer and use it in GitHub Desktop.
Save cisoun/3debd1376dc261585af829bb07b7b4b8 to your computer and use it in GitHub Desktop.
Shell script to mount a disk on RAM with a specific name and size on Mac OS X
#!/bin/bash
#
# Create a virtual disk on RAM with a given name and size.
# To remove it, just unmount it in Finder.
#
# Usage: ram.sh <name> <size in MB>
#
function usage() {
echo "$0 <name> <size in MB>"
}
if [[ $# -lt 2 ]]; then
usage
exit 1
fi
if ! [[ $2 =~ ^[0-9]+$ ]]; then
echo "size must be a numeric value" >&2
exit 1
fi
name=$1
size=$2
device=$(hdiutil attach -nobrowse -nomount ram://$(($size*2048)))
diskutil erasevolume HFS+ $name $device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment