Skip to content

Instantly share code, notes, and snippets.

@algobardo
Forked from rxin/ramdisk.sh
Last active September 8, 2015 08:55
Show Gist options
  • Save algobardo/982a5846b098985bbd8a to your computer and use it in GitHub Desktop.
Save algobardo/982a5846b098985bbd8a to your computer and use it in GitHub Desktop.

Revisions

  1. @rxin rxin revised this gist Mar 4, 2013. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions ramdisk.sh
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,8 @@ E_BADARGS=99
    if [ $# -ne $ARGS ] # correct number of arguments to the script;
    then
    echo " "
    echo "To create a RAMDISK -> Usage: `basename $0` [create] SIZE_IN_MB"
    echo "To delete a RAMDISK -> Usage: `basename $0` [delete] DISK_ID"
    echo "To create a RAMDISK -> Usage: `basename $0` create SIZE_IN_MB"
    echo "To delete a RAMDISK -> Usage: `basename $0` delete DISK_ID"
    echo " "
    echo "Currently this script only supports one RAMDISK. Will update soon."
    echo "DISK_ID can be shown with 'mount'. usually /dev/disk* where * is a number"
    @@ -24,15 +24,14 @@ then
    echo "Create ramdisk..."
    RAMDISK_SIZE_MB=$2
    RAMDISK_SECTORS=$((2048 * $RAMDISK_SIZE_MB))
    DISK_ID=$(hdid -nomount ram://$RAMDISK_SECTORS)
    DISK_ID=$(hdiutil attach -nomount ram://$RAMDISK_SECTORS)
    echo "Disk ID is :" $DISK_ID
    newfs_hfs -v Ramdisk ${DISK_ID}
    diskutil mount ${DISK_ID}
    diskutil erasevolume HFS+ "ramdisk" ${DISK_ID}
    fi

    if [ "$1" = "delete" ]
    then
    echo "Delete/unmount ramdisk"
    echo "Delete/unmount ramdisk $2"
    umount -f $2
    hdiutil detach $2
    fi
    fi
  2. @rxin rxin created this gist Mar 4, 2013.
    38 changes: 38 additions & 0 deletions ramdisk.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/bin/bash

    # From http://tech.serbinn.net/2010/shell-script-to-create-ramdisk-on-mac-os-x/
    #

    ARGS=2
    E_BADARGS=99

    if [ $# -ne $ARGS ] # correct number of arguments to the script;
    then
    echo " "
    echo "To create a RAMDISK -> Usage: `basename $0` [create] SIZE_IN_MB"
    echo "To delete a RAMDISK -> Usage: `basename $0` [delete] DISK_ID"
    echo " "
    echo "Currently this script only supports one RAMDISK. Will update soon."
    echo "DISK_ID can be shown with 'mount'. usually /dev/disk* where * is a number"
    echo " "
    echo " "
    exit $E_BADARGS
    fi

    if [ "$1" = "create" ]
    then
    echo "Create ramdisk..."
    RAMDISK_SIZE_MB=$2
    RAMDISK_SECTORS=$((2048 * $RAMDISK_SIZE_MB))
    DISK_ID=$(hdid -nomount ram://$RAMDISK_SECTORS)
    echo "Disk ID is :" $DISK_ID
    newfs_hfs -v Ramdisk ${DISK_ID}
    diskutil mount ${DISK_ID}
    fi

    if [ "$1" = "delete" ]
    then
    echo "Delete/unmount ramdisk…"
    umount -f $2
    hdiutil detach $2
    fi