2020/01/04

hdiutil Error 110: image not recognized

A script to keep a disk image (AKA dmg) mounted, was suddenly failing - silently.

(Why create such a script? In this use-case, the image / volume should only be mounted when the app using it, is frontmost and might need it; otherwise it should be dismounted - so that it may be safely mounted by another Mac. Since there's no file-locking in this scenario, mounting it on multiple Macs simultaneously, can result in conflicts. Since this is a sparsebundle, conflicts result in multiple bands, which is usually (somewhat) straightforward to sort out - but manually, and who wants that?)

I ran the script in a debug / trace mode (bash -x) and saw nothing interesting - except then I noticed:

hdiutil attach -quiet -noautoopen /path/here

Ah yes; after debugging the previous issue, I'd set -quiet, to make the output cleaner.

(BTW: The -noautoopen option is handy, since without it, the Finder otherwise can open a window for the top level of the volume - right in front of whatever it was you were working on.)

So I ran that command with -verbose instead - and got this error message:

Error 110 (image not recognized).

Which didn't get me far; I couldn't find any references that helped, especially since the image mounted OK from the GUI - at which point I realized the problem:

It worked in the GUI, because /path/here was an alias - however the script did not know how to resolve an alias; it needed a symlink instead - which the GUI happily also recognizes. A symlink just isn't be able to auto-update, as an alias can, if the target is moved. (Side note: symlinks can be _much_ smaller; handy on a small filesystem.)