Skip to content

Instantly share code, notes, and snippets.

@htr3n
Last active November 21, 2024 14:59
Show Gist options
  • Save htr3n/344f06ba2bb20b1056d7d5570fe7f596 to your computer and use it in GitHub Desktop.
Save htr3n/344f06ba2bb20b1056d7d5570fe7f596 to your computer and use it in GitHub Desktop.
Creating RAM disk in macOS

Built-in

diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nobrowse -nomount ram://XXXXX`

where XXXXX is the size of the RAM disk in terms of memory blocks.

Notes:

$2048$ memory blocks correspond to 1MB. Thus, XXXXX = YYYY * 2048 where YYYY is the size in MB.

E.g.

  • ram://2048 will create 1MB RAM disk
  • ram://2097152 --> 1 GB
  • ram://4194304 --> 2 GB
  • ram://8388608 --> 4 GB

Third-party Tools

  • TmpDisk:: Open Source RAM disk management app.
  • Ultra RAM Disk installs as a menu bar item that allows you to create RAM disks when needed.
  • RAMDisk: is an app for creating as well as backing up RAM disks, to allow you to save their contents as well as restore RAM disks when you restart your Mac.
  • RAMDiskCreator

Resources

@kvaDrug
Copy link

kvaDrug commented Aug 14, 2021

In order to unmount such disk I use diskutil unmount /dev/rdisk3 then diskutil unmountDisk /dev/disk3. Is this a correct way?

@boatcoder
Copy link

boatcoder commented Sep 4, 2021

@kvaDrug. hdiutil detach /dev/disk2 works for me

@productdevbook
Copy link

productdevbook commented Sep 19, 2021

@kvaDrug. hdiutil detach /dev/disk2 works for me

diskutil erasevolume HFS+ 'RAM Disk' disk0 `hdiutil detach /dev/disk0 -nobrowse -nomount ram://33554415`

thats true ?

@iamqk
Copy link

iamqk commented Jun 12, 2023

use APFS instead of HFS+, you may gain a better performance(based on test with Blackmagic)

@anki-code
Copy link

anki-code commented Jul 15, 2024

The same for xonsh shell:

diskutil erasevolume HFS+ 'myramdisk' @$(hdiutil attach -nobrowse -nomount ram://@(2097152*1))
ls /Volumes/myramdisk
hdiutil detach @($(df | grep ram1g).split(' ')[0])

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