Skip to main content
added 573 characters in body
Source Link
jksoegaard
  • 79.6k
  • 4
  • 133
  • 204

Start by finding the device node for your RAM disk by running the following in the Terminal:

diskutil list

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:

mkdir ~/MyReadOnlyMountPoint
mount -o ro /dev/disk3 ~/MyReadOnlyMountPoint

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:

bindfs --perms=a-w MyMountPoint MyReadOnlyMountPoint.

Start by finding the device node for your RAM disk by running the following in the Terminal:

diskutil list

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:

mkdir ~/MyReadOnlyMountPoint
mount -o ro /dev/disk3 ~/MyReadOnlyMountPoint

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.

Start by finding the device node for your RAM disk by running the following in the Terminal:

diskutil list

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:

mkdir ~/MyReadOnlyMountPoint
mount -o ro /dev/disk3 ~/MyReadOnlyMountPoint

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:

bindfs --perms=a-w MyMountPoint MyReadOnlyMountPoint.
Source Link
jksoegaard
  • 79.6k
  • 4
  • 133
  • 204

Start by finding the device node for your RAM disk by running the following in the Terminal:

diskutil list

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:

mkdir ~/MyReadOnlyMountPoint
mount -o ro /dev/disk3 ~/MyReadOnlyMountPoint

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.