MacOS – Change “ignore ownership on this volume” from the command line for Mac OS X volume

hfs+macossparsebundle

(This question is a spin-off of another question I asked on this site.)

New images always ignore owner/group

When creating a new disk image from Disk Utility it is automatically mounted. If you then select the volume in Finder and press Cmd-I (for the info window) you will see this at the bottom of the window:

enter image description here

This means that file owners and groups will be ignored on this volume. This is very convenient for external drives being shared between machines with different user accounts on them. For a backup volume it is not a good idea as you would like to retain the owner/group information for the files backed up.

Change this from Finder

To change this, simply uncheck the checkbox and it will remembered after you eject and remount the image.

Change from command line (Terminal)

Instead of mounting the image from Finder, you can also mount it from the command line using this command (assuming the image is called testimage.sparsebundle):

$ hdiutil attach testimage.sparsebundle/

Still, owners are ignored on the volume. Adding the -owners on option is (almost) equivalent to unchecking the checkbox in the image above:

$ hdiutil attach -owners on testimage.sparsebundle/

However, after unmounting and remounting the volume from Finder (or from the command line without the -owners on option), the checkbox is checked again.

Does anybody know how to make this change persistent using a command-line call?

Best Answer

You use diskutil for that. See diskutil(1) under enableOwnership and disableOwnership. Note that this setting is specific to a particular operating system installation, since it is stored in /var/db/volinfo.database. I.e., if you copy the disk image to a new computer the setting won't persist, but it does persist across reboots, mounts, umounts, etc. all on a single computer.

Use diskutil to find the identifier, then change the option:

$ diskutil list
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            Disk Image             *41.0 MB    disk2
$ sudo diskutil enableOwnership disk2
File system user/group ownership enabled