I have a disk image with my main media library inside it, but I normally only mount this as read-only, as this prevents applications from touching anything inside (which can cause a lot of band files to be copied into backups unnecessarily).
When I want to add data to the image, I re-mount it as read/write, add the new content, then allow plenty of time for mdworker etc. to index the changes, before switching back to read-only (or unmounting).
So even when the image is mounted read-only, there will still be a full Spotlight index within it, that Spotlight should be able to use.
Problem is… it doesn't.
The command I prefer to mount the image with is as follows:
hdiutil attach -mountpoint /path/to/mount /path/to/image mount -uro noatime,nobrowse /path/to/mount
I prefer to do it this way, as it allows me to then easily make the mounted volume read-write, then read-only again like so:
mount -uwo noatime,nobrowse /path/to/mount # Add files, let Spotlight do its thing mount -uro noatime,nobrowse /path/to/mount
However, when the volume is made read-only using the
mount command, Spotlight doesn't seem able or willing to access its own index. Querying with
mdutil gives the following:
mdutil -s /path/to/mount /path/to/mount: Error: unknown indexing state.
The alternative way to mount the disk-image as read-only is to mount the entire image device that way, using the following alternate command:
hdiutil attach -readonly -mountpoint /path/to/mount /path/to/image
Strangely, Spotlight works just fine when the image is mounted in this way, even though the entire device (and thus the mounted volume) is just as read-only as before.
The problem with mounting in this way though is that there's no easy way to switch to read/write, as
mount -uwo noatime,nobrowse /path/to/mount fails, even for root (this appears to be a specific feature of
-readonly option). This means the image must be fully detached/ejected then re-mounted, which I would prefer not to have to do.
So my question is; is it possible to mount a disk image as read-only, but in such a way that it can not only still be made read/write easily (without ejecting) and also without breaking Spotlight?
And yes, I realise I probably shouldn't be working with a disk-image in this way in the first place, but they make it super easy to back stuff up to a non-HFS+ volume (e.g- a Linux NAS via rsync).