Skip to content

Instantly share code, notes, and snippets.

@htr3n
Last active October 23, 2026 03:09
Show Gist options
  • Select an option

  • Save htr3n/344f06ba2bb20b1056d7d5570fe7f596 to your computer and use it in GitHub Desktop.

Select an option

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

@floer32

floer32 commented Mar 2, 2021

Copy link
Copy Markdown

Update in 2021: it seems that TmpDisk is the only GUI option now. At least, for me.

@kvaDrug

kvaDrug commented Aug 14, 2021

Copy link
Copy Markdown

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

@boatcoder

boatcoder commented Sep 4, 2021 •

Copy link
Copy Markdown

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

@productdevbook

productdevbook commented Sep 19, 2021 •

Copy link
Copy Markdown

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

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

thats true ?

ghost commented Jun 12, 2023

Copy link
Copy Markdown

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

@anki-code

anki-code commented Jul 15, 2024 •

Copy link
Copy Markdown

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])

@johnalanwoods

Copy link
Copy Markdown

Built a modern version here, supports APFS: https://github.com/johnalanwoods/RAMDisk

@eirnym

eirnym commented Jul 14, 2026 •

Copy link
Copy Markdown

mount at very specific mount point.

Please tell me if you know how do the same, but with JHFS+ and without EFI partition.

Adjust commands for actual values

$ hdiutil attach  -nomount  -mountroot target  ram://8388608 
/dev/disk6
$ diskutil apfs createContainer /dev/disk6  
Creating container with disk6
Started APFS operation on disk6
Creating a new empty APFS Container
Unmounting Volumes
Switching disk6 to APFS
Creating APFS Container
Created new APFS Container disk7
Disk from APFS operation: disk7
Finished APFS operation on disk6
$ diskutil apfs addVolume disk7 apfs name -nomount  
Will export new APFS Volume "name" from APFS Container Reference disk7
Started APFS operation on disk7
Preparing to add APFS Volume to APFS Container disk7
Creating APFS Volume
Created new APFS Volume disk7s1
Disk from APFS operation: disk7s1
Finished APFS operation on disk7
$ hdiutil attach -mountpoint /your/target/path /dev/disk7s1 
/dev/disk7s1        	41504F50-0000-11AA-AA11-00306B4 /your/target/path

@eirnym

eirnym commented Jul 15, 2026

Copy link
Copy Markdown

mount_tmpfs also works, but it require root privileges

@samleb

samleb commented Aug 8, 2026 •

Copy link
Copy Markdown

Since tmpfs dropped on macOS 15 (Sequoia), you can also use it to create RAM disks, and this approach has two massive advantages over the hdiutil/diskutil-based implementations:

  • Incomparable performance: around 11 MB/s read/write on my M1 Max Mac Studio (makes sense since it's basically a native filesystem directly managed by the VM)
  • Dynamic RAM allocation: RAM isn't "reserved" ahead of time, but usage grows with the amount of data you put on the RAM disk (10 MB of data on a 10 GB RAM disk = 10 MB of RAM used)

You can easily mount a tmpfs volume with the following commands:

  • sudo mount_tmpfs -s 10G path/to/dir — mounts the volume and temporarily hides the original folder contents
  • sudo chown $(whoami):staff path/to/dir — to get write permissions back inside the volume

Same goes for unmounting:

  • sudo umount path/to/dir — heads up, all volume contents vanish instantly, original folder files reappear

To bypass these mount/unmount "hiccups", I built a utility called RAM Folder that turns any of your folders into a tmpfs volume by importing the data into it when mounting, and saves the volume's contents back to the folder when unmounting.

Turns out the transition between a standard folder and a RAM disk is so seamless that I decided to call it: RAM Folder.

It's not open-source (yet) but you can check it out on the RAM Folder product page and there's a 14-day trial free trial.
It's super performant for build caches, hosting a unit test DB, or honestly any operation that's IO-bound.

Hope you find this interesting and take the time to give the utility a spin!

@kvaDrug

kvaDrug commented Aug 15, 2026

Copy link
Copy Markdown

Please, report the above comment by samleb as spam!

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