1

I use a 200MB Ram disk to write some throwaway files that I use repeatedly but can forget from run to run and don't mind losing on a shutdown. I often run out of space however and have to clean house.

This comes from a typical recommendation to mount a RAM disk until Macos:

  • can I use APFS instead? Would there be much benefit in a Ramdisk? Would it compress?

  • can I activate compression by default? I am dumping out a bunch of throw-away diagnostic HTML files that would take a lot less space if there was transparent file system compression like you can do on NTFS.

                  old-school, what about APFS?
                     πŸ‘‡
diskutil erasevolume HFS+ 'RAMDisk' `hdiutil attach -nomount ram://409600`

Diskutil itself doesn't help much:

Not one mention of APFS.

$ diskutil erasevolume -h

Usage:  diskutil eraseVolume format name MountPoint|DiskIdentifier|DeviceNode
Erase a single disk partition or whole, laying down a new file system volume
that will be empty of files. Format is the specific file system personality
name of the new volume, e.g. "Journaled HFS+" or a common alias e.g. "jhfs+".
Name is the new volume name (subject to file system naming restrictions) or
can be specified as %noformat% to skip initialization (to skip newfs). You
cannot erase the boot volume. A pseudo-format of "free" or "Free Space" will
remove the partition altogether, leaving a free space gap in the partition map.
Ownership of the affected disk is required.
Examples: diskutil eraseVolume JHFS+ UntitledHFS /Volumes/SomeDisk
          diskutil eraseVolume "Journaled HFS+" FooWholeVolEgRaid disk7
          diskutil eraseVolume ms-dos FOO disk0s5
          diskutil eraseVolume free free disk0s5

Not much documentation from Apple - it's terminal stuff.

Looking at man page we still only have old file systems.

Here's what using the GUI has to say:

enter image description here

Compressed Disk Images. what's that?

I have also seen the term compressed disk image with regards to macos. Does it have any relevance here?

giving it a try didn't help much:

Mount a 50MB

diskutil erasevolume APFS 'ram2'hdiutil attach -nomount ram://102400``

output: No clear error, but no disk either:
Started erase on disk2
Unmounting disk
Erasing
Mounting disk
Could not mount disk2 after erase πŸ‘ˆ not good
Finished erase on disk2
ls /Volumes doesn't show a ram2 disk
total 0
drwxr-xr-x+  4 root  wheel  128 Feb 26 16:03 .
drwxr-xr-x  28 root  wheel  896 Sep 30 13:10 ..
lrwxr-xr-x   1 root  wheel    1 Feb  8 12:51 MacHD -> /
drwxrwxr-x   8 jluc  staff  340 Feb 14 23:01 RAMDisk πŸ‘ˆ existing one
3
  • 1
    diskutil partitionDisk $(hdiutil attach -nomount ram://SIZE) 1 GPTFormat APFS 'RAMDisk' '100%'. SIZE=number of 512 Byte blocks (i.e. 200 MiB = 409600 blocks) – klanomath Feb 27 '20 at 23:15
  • where are you closing the $( parenthesis? '100%') ? or, after SIZE? – JL Peyret Feb 27 '20 at 23:24
  • 1
    After SIZE: hdiutil attach -nomount ram://SIZE just creates a new device node (e.g. /dev/disk2) which is partitioned with the diskutil ... command – klanomath Feb 27 '20 at 23:54
1

@klanomath has the correct command in the comments above.

diskutil partitionDisk $(hdiutil attach -nomount ram://SIZE) 1 GPTFormat APFS 'RAMDisk' '100%'

My results:

$ diskutil partitionDisk $(hdiutil attach -nomount ram://12128430) 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.2 GB     disk15
   1:                        EFI EFI                     209.7 MB   disk15s1
   2:                 Apple_APFS Container disk16        6.0 GB     disk15s2

enter image description here

5
  • 1
    You are mixing disk size and partition size. If you want a final size of 6 GB for the APFS container you'd have to divide 6 GB through 512 (= 11718750 blocks) add 2 x 40 blocks for the 1st and 2nd partition table (and some free space) and 409600 blocks for the EFI: 12128430 blocks! – klanomath Apr 15 '20 at 10:27
  • @klanomath You are absolutely correct. I am editing "my" answer to remove the confusion. Could you please explain how you found what size the partition tables required, and how you predicted the size of the EFI? Also why does it show as 6.3 GB Available (318.1 MB purgeable)? – John Apr 15 '20 at 19:18
  • 1
    512 Byte blocks are aligned to 4k physical blocks: The 1st partition table contains 1 MBR block + 1 GPT header block + 32 blocks GPT table + 6 empty blocks (to fulfill the 4k boundary). The second partition table: 7 empty blocks (to fulfill the 4k boundary) + 32 blocks GPT table + 1 GPT header block. The standard Apple EFI of a 512Byte/4k emulated device (even RAM!) has the size 409600 blocks. – klanomath Apr 15 '20 at 19:20
  • You have deep knowledge of this subject. If you have a minute can you explain why there would be 6.3 GB "Available" with (318.1 MB purgeable) on a freshly created and unused RAM Disk. Apparently "Available" is not synonymous with capacity. – John Apr 15 '20 at 19:24
  • Buy 6 GB and get a whopping 0.3 GB extra for free (always only today)! I have no clue...what's wrong here – klanomath Apr 15 '20 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .