Created
February 13, 2022 19:24
-
-
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.
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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to
chmod -x mkramdisk
to make it executable.Usage:
ramdisk 'RamDiskNameHere' 8