Create APFS RAM disk on macOS High Sierra

MShekow picture MShekow · Sep 14, 2017 · Viewed 10.7k times · Source

usually creating RAM disks works with the following commands

hdid -nomount ram://<blocksize>

Returns e.g. /dev/disk2 Then I would format the disk, with say

newfs_hfs /dev/disk2

followed by mounting it:

mount -t hfs /dev/disk2 /some/mount/target

This procedure doesn't seem to work with APFS. I'm on High Sierra beta 9. The mount command doesn't output any error, but the path is not mounted.

In my case, after the hdid command finished, newfs_apfs -i /dev/disk2 yields

nx_kernel_mount:1364: checkpoint search: largest xid 1, best xid 1 @ 1
nx_kernel_mount:1422: sanity checking all nx state... please be patient.
spaceman_metazone_init:278: no metazone for device 0, of size 209715200 bytes, block_size 4096
apfs_newfs:18075: FS will NOT be encrypted.

When I then enter mount -t apfs /dev/disk2 /some/target/path then the mount commands seems to work for 2 seconds, doesn't give any output and the mount was NOT succesful.

Can anyone tell me how to actually make a APFS RAM disk s.t. it works? :p

PS: I've also tried something like diskutil partitionDisk /dev/disk2 GPT APFS myvolumename 0b which does mount the volume to /Volumes/myvolumename but creates yet another disk (disk3 in this case) which seems odd to me!

Answer

unrivaledcreations picture unrivaledcreations · Nov 17, 2017

@Glyph provided the best answer in a comment to the accepted answer, but it deserves its own answer:

diskutil partitionDisk $(hdiutil attach -nomount ram://$((2048*sizeInMB))) 1 GPTFormat APFS 'Ramdisk' '100%'

Change sizeInMB to your desired size.

I've updated Glyph's answer to simplify the volume name a little.