Created
October 17, 2017 23:57
-
-
Save petrowsky/6f64a064622630504e253a2a094c86fe to your computer and use it in GitHub Desktop.
A shell function for creating a RAM disk of arbitrary size. Add to your bash (or other shell) profile.
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
ramdisk () { | |
test "$1" || 1=2 | |
DISK_NAME="RamDisk" | |
MAX_SIZE=6 | |
DISK_SIZE=$((${1}*1024*1024*1024/512)) | |
DISK_FOUND=`df | grep -o $DISK_NAME` | |
if [[ $1 -gt $MAX_SIZE ]] | |
then | |
echo "NOTICE: Can't create a ram disk larger than $MAX_SIZE GB" | |
return | |
fi | |
if [[ $DISK_FOUND = $DISK_NAME ]] | |
then | |
echo "NOTICE: A disk named $DISK_NAME already exists!" | |
return | |
fi | |
if ! [[ $1 =~ '^[0-9]+$' ]] | |
then | |
echo "NOTICE: Supply a number between 1 and $MAX_SIZE" | |
return | |
fi | |
diskutil erasevolume HFS+ $DISK_NAME `hdiutil attach -nomount ram://$DISK_SIZE` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment