Going a bit further with the loopback files, I decided to experiment with RAM filesystems on OS X. Quite simple, and I created a couple of scripts to automate creation and removal of RAM disks. Nothing fancy, but figured I’d share.
ramfs-create.sh – first parameter is amount of ram to use in mb, second parameter is optional and is the disk name. (no spaces) By default it’s called “RAMDisk”.
ramfs-remove.sh – first parameter is optional, and is the disk name. It defaults to “RAMDisk” if no parameter is provided.
ramfs-create.sh
#!/bin/sh
if [ -z $1 ]; then
echo “parameters necessary.”
echo “$0 [ ram use in Mb ] <Disk Name>”
exit 1
fi
NAME=”RAMDisk”if [ ! -z $2 ]; then
echo “Name being set to something different”
NAME=$2
fi
RAM=$( expr $1 \* 2048 );
diskutil erasevolume HFS+ “${NAME}” `hdiutil attach -nomount ram://${RAM}`
ramfs-remove.sh
#!/bin/sh
NAME=RAMDisk
if [ ! -z $1 ]; then
NAME=$1
fidiskutil unmount “${NAME}”
DISK=`diskutil list | grep -i ${NAME} | awk ‘{ print $5 }’`
hdiutil detach /dev/${DISK}