I created an APFS RAM disk on macOS X 10.14 Mojave using these commands:
diskutil partitionDisk $(hdiutil attach -nomount ram://12582912) 1 GPTFormat APFS 'RAMDisk' '100%'
Which should create a 6 GB RAM Disk. I ended up with a "6.53 GB" Ram Disk. The question is does hdiutil
calculate block sizes as 512 bytes or 500 bytes?
The old way was:
1 block = 512 bytes
2 blocks = 1024 bytes (KB)
1024 bytes X 1024 = 1048576 bytes (MB)
1048576 bytes x 1024 = 1073741824 bytes (GB)
1073741824 bytes / 512 = 2097152 blocks per GB
But maybe storage is now calculated differently:
1 block = 500 bytes
2 blocks = 1000 bytes (KB)
1000 bytes X 1000 = 1000000 bytes (MB)
1000000 bytes x 1000 = 1000000000 bytes (GB)
1000000000 bytes / 500 = 2000000 blocks per GB
EDIT: Just tested this myself and ended up with these numbers which seems to indicate that hdiutil
does indeed use 500 byte block size for calculation. There is some overhead for EFI which reduces available size but the GUID partition was 6.1 GB.
$ diskutil partitionDisk $(hdiutil attach -nomount ram://12000000) 1 GPTFormat APFS 'RAMDisk' '100%'
Started partitioning on disk15
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk15s2 as APFS with name RAMDisk
Mounting disk
Finished partitioning on disk15
/dev/disk15 (disk image):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme +6.1 GB disk15
1: EFI EFI 209.7 MB disk15s1
2: Apple_APFS Container disk16 5.9 GB disk15s2