Read-only RAM disk can be created with method described in this post, so how to create a read-only shadow mount point for existing RAM disk while keeping the original mount point unchanged with command line on macOS Catalina?
How to create a read-only shadow for existing RAM disk on macOS
command linediskutilhdiutilmemorymount
Related Question
- MacOS – How to mount an encrypted disk image so that it is read-write
- How to create a read-only RAM disk on macOS from the command line
- Mac – Create encrypted partition for Time Machine from command line using diskutil or gpt, instead of Disk Utility
- MacOS – How to calculate RAM disk size on OS X Mojave—500 or 512 byte block size
- Hdiutil attach -shadow not working
Best Answer
Start by finding the device node for your RAM disk by running the following in the Terminal:
You'll find that the ram disk is probably listed as something like disk3, disk4 or similar.
Then mount the RAM disk as read-only:
I assume that you have formatted the whole RAM-disk with your file system. If you have created instead an APFS container with an APFS volume inside, you'll want to use the volume device node instead (suck as disk3s1 or similar).
Note that you'll only want to mount the RAM-disk once at a time. macOS does not natively support the bind mounting feature of Linux that you mention in your question.
If you need to have the RAM-disk mounted twice (i.e. you cannot use symlinks, file permissions or other means to achieve what you need) - you could look into non-native options such as bindfs or osxfs to be able to mount the RAM-disk into two places at the same time. Performance will be different though.
For example with bindfs, you can easily provide an extra read-only mount point for you RAM-disk like this: