Created
May 5, 2017 13:21
-
-
Save brandhill/3d520f32fcf4bd2eed83149a8035fae8 to your computer and use it in GitHub Desktop.
create/delete a ramdisk on mac
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 | |
# 只要執行 mount_ramdisk.sh 就會建立一個 4GB 的 RAM disk, | |
# 執行 mount_ramdisk.sh 2 就會建立一個 2GB 的 RAM disk, | |
# 執行 mount_ramdisk.sh -u 就可以卸載掉 RAM disk: | |
RAM_DISK_GB=4 | |
RAM_DISK_NAME=RamDisk | |
MOUNTED_RAM_DISK_FOLDER="/Volumes/${RAM_DISK_NAME}" | |
# Unmount RAM disk | |
if [ "$1" = "-u" ]; then | |
if [ -e "${MOUNTED_RAM_DISK_FOLDER}" ]; then | |
hdiutil detach "${MOUNTED_RAM_DISK_FOLDER}" | |
else | |
echo "RAM disk is not mounted yet." | |
fi | |
exit | |
fi | |
# Get RAM disk size from parameter | |
if [ "$1" != "" ]; then | |
RAM_DISK_GB="$1" | |
fi | |
if [ -e "${MOUNTED_RAM_DISK_FOLDER}" ]; then | |
echo "RAM disk is already mounted on ${MOUNTED_RAM_DISK_FOLDER}." | |
else | |
diskutil erasevolume HFS+ "${RAM_DISK_NAME}" $(hdiutil attach -nomount ram://$((RAM_DISK_GB*1024*2048))) | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment