There are various resources about how to create a RAM disk, but they all deal with HFS+ RAM disks. But how does one create an APFS RAM disk?
I tried passing APFS
as file system to the diskutil
command like below, but that doesn't work. Since diskutil
has a whole bunch of APFS-related subcommands I assume there's more magic necessary.
DISK_ID=`hdiutil attach -nomount ram://$((4 * 1024 * 2048))`
diskutil eraseVolume APFS "RAM Disk" "$DISK_ID"
Best Answer
It works if you create a JHFS+ volume first and convert it to APFS in a second step:
DISK_ID=$(hdiutil attach -nomount ram://$((<number_of_blocks>)))
diskutil eraseDisk JHFS+ "RAM Disk" $DISK_ID
diskutil apfs convert $(tr -d ' '<<<${DISK_ID}s2)
If the RAM disk has a size of 2 GiB (4 * 1024 * 1024)(block_size) or smaller no EFI partition is created and the 3rd command is:
diskutil apfs convert $(tr -d ' '<<<${DISK_ID}s1)
or more generally:Result: