Skip to content

Instantly share code, notes, and snippets.

@nolochemical
Created April 14, 2020 19:32
Show Gist options
  • Save nolochemical/faf2bd404721ee2ddb6e351f7163b1d0 to your computer and use it in GitHub Desktop.
Save nolochemical/faf2bd404721ee2ddb6e351f7163b1d0 to your computer and use it in GitHub Desktop.
RamdiskScript ( Mac )
RD_SIZE=600 #MB
print_usage() {
echo "\n *With great power comes great responsibility* \n\nUsage: $0 \n -c create a ramdisk with -n <diskname>\n -d delete a disk with -n <diskname>\n Manually *Caution*: \n $ hdiutils detach /dev/<diskname> \n\nAll Mounted Disks\n=================\n`mount | sort`\n=================\n " 1>&2; exit 1;
}
while getopts 'n:cdv' flag; do
case "${flag}" in
n) if [ -z "$flag" ]; then
echo Please enter a disk name
exit
else NAME=${OPTARG}
fi
;;
c) diskutil erasevolume HFS+ ramdisk-$NAME `hdiutil attach -nomount ram://$((RD_SIZE*2048))`
cd /Volumes/ramdisk-$NAME
exit
;;
d) hdiutil detach /Volumes/ramdisk-$NAME
exit
;;
*) print_usage
exit 1 ;;
esac
done
@nolochemical
Copy link
Author

  1. touch Ramdisk.sh
  2. copy and paste
  3. chmod + x Ramdisk.sh // make executable
  4. ./Ramdisk.sh -n MyRamDisk -l
    ./ramdisk.sh: illegal option -- l

With great power comes great responsibility

Usage: ./ramdisk.sh
-c create a ramdisk with -n
-d delete a disk with -n
Manually Caution:
$ hdiutils detach /dev/

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