Skip to content

Instantly share code, notes, and snippets.

@jikuja
Created June 14, 2024 06:44
Show Gist options
  • Save jikuja/7785a29a8bc452def7dec81dd6908c72 to your computer and use it in GitHub Desktop.
Save jikuja/7785a29a8bc452def7dec81dd6908c72 to your computer and use it in GitHub Desktop.
OS X RAMDISK usage

OS X RAMDISK Usage

Before creating large disks check from Apple documentation if memory is de-allocated after hdiutil detach1

This guide has only CLI steps: using GUI tools might work but not covered here.

Create a new RAM disk device

hdiutil attach -nomount ram://2097152
  • creates a new “disk“ with 1 GB space
  • given unit is 512 bytes
    • 2048 units = 1 MB
    • 2097152 units = 1 GB
    • more unit examples on 1
  • the command return device it created. E.g. /dev/disk4

Format the new device

diskutil list
  • lists available disks and volumes
  • doublecheck name of the device
diskutil erasevolume HFS+ "RAMDisk" <device>
  • formats device/volume
  • <device> must match with the output of hditil attach ... command
  • disk is automatically mounted on /Volumes/RAMDisk

Use the device

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

After using RAMDisk scratch it

Unmount device

umount -f <device>

Delete RAMDISK

hdiutil detach <device>

Footnotes

  1. https://apple.stackexchange.com/a/461890/326117 2

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