Ramdisk on macOS Mojave/Catalina?
What is the modern way the create a ramdisk on macOS Mojave or Catalina?
Specifically, how to:
- create a ramdisk for one-time use, discarded when shutting down the Mac?
- dismount & destroy the ramdisk, freeing up memory?
- create an empty ramdisk automatically when booting the Mac?
- create a ramdisk with a few specific folders created, when booting the Mac?
- Persist the content of a ramdisk when shutting down a Mac, and reload that content into a ramdisk when the Mac starts again?
Also… On Mojave/Catalina, would the newer APFS file system be more appropriate for a ramdisk than HFS+ file system?
Example of old solutions for a 1-gig drive (1 gig = 1024 * 2048 = 2097152) named `RamDisk`:
diskutil erasevolume HFS+ 'RamDisk' `hdiutil attach -nomount ram://2097152`
I have also found this snippet that seems to be using the APFS file system. But I don't understand the parts, and don't know if this is a proper way or not.
diskutil partitionDisk $(hdiutil attach -nomount ram://2097152) 1 GPTFormat APFS 'RamDisk' '100%'