On macOS Catalina, a RAM disk with 512MB space can be created with the following command:
diskutil eraseVolume HFS+ "RAMDisk" `hdiutil attach -nomount ram://1048576`
On Ubuntu, a RAM disk and its read-only shadow can be created by:
mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk
mount -t aufs -o br:/mnt/ramdisk=ro none /mnt/readonly
So how can I create a read-only RAM disk on macOS Catalina with command line like this, or create a read-only shadow of existing RAM disk?
Best Answer
Get the device number of the RAM disk:
diskutil list
(e.g. disk3)Add some content to the RAM disk ?.
diskutil umount disk3
diskutil mount readOnly /dev/disk3
.Apply the disk number according to your environment!
unmount/mount
works for an HFS+ disk (in case of a RAM disk)/volume or an APFS volume onlyunmountDisk/mountDisk
works for HFS+ disks and APFS container schemes.If you format the RAMDisk as APFS container and one APFS volume
you can either mount the APFS container scheme or the APFS volume:
diskutil list
(e.g. disk4)diskutil umountDisk disk4
diskutil mountDisk readOnly /dev/disk4
or the RAM disk's APFS volume:
diskutil umount disk4s1
diskutil mount readOnly /dev/disk4s1
As one-liner for an HFS+ volume with the unique name RAMDisk:
As one-liner for an APFS volume with the unique name RAMDisk:
Thanx to user3439894 for all his hints & comments...