Skip to content

Instantly share code, notes, and snippets.

@kana
Created April 26, 2024 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kana/8f2bd18badc9321d788c16401d6f1f26 to your computer and use it in GitHub Desktop.
Save kana/8f2bd18badc9321d788c16401d6f1f26 to your computer and use it in GitHub Desktop.
Create a RAM disk on macOS.
#!/bin/bash
set -euxo pipefail
MB=100
NUMSECTORS=$((MB * 1024 * 1024 / 512)) # A sector is 512 bytes.
# "hdiutil attach" outputs extra spaces/tabs. They must be removed.
MYDEV="$(hdiutil attach -nomount "ram://$NUMSECTORS" | sed 's/[ \t]*$//')"
diskutil eraseVolume APFS "ramdisk-${MB}mb" "$MYDEV"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment