Skip to content

Instantly share code, notes, and snippets.

@typesend
Created February 13, 2022 19:24
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 typesend/e8603f762d1840fc8228966010a21c5b to your computer and use it in GitHub Desktop.
Save typesend/e8603f762d1840fc8228966010a21c5b to your computer and use it in GitHub Desktop.
A simple shell script to create a ramdisk under macOS. Tested under Monterey 12.1. Note that it takes two shell arguments, first the name of the ramdisk and secondly the desired size in GB.
#!/bin/sh
diskName=${1:-'RamDisk'}
gigsRequested=${2:-4}
bytes=$(expr 2097152 \* $gigsRequested)
echo "Starting to make $gigsRequested GB ramdisk named $diskName..."
if diskutil erasevolume HFS+ $diskName $(hdiutil attach -nomount ram://$bytes); then
open "/Volumes/${diskName}"
echo "Success!"
else
echo 'Error: Unable to make ramdisk'
exit 1
fi
@typesend
Copy link
Author

Don't forget to chmod -x mkramdisk to make it executable.

Usage:
ramdisk 'RamDiskNameHere' 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment