Question

(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?

Was it helpful?

Solution

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

OTHER TIPS

I found that both answers worked for enabling ownership in way that is remembered:

sudo diskutil enableOwnership <diskname>s<slicenum>

And:

vsdbutil -a /Volume/<volname>

However, the opposite is not true, at least on OS X 10.11.3:

sudo diskutil disableOwnership <diskname>s<slicenum>

And:

vsdbutil -d /Volume/<volname>

Both temporarily change the state, but ownership is re-enabled next time I mount the volume. This appears to be a bug in the operating system. Fortunately I found a solution that works. Eject all external disks that you want to disable ownership for. Then delete the appropriate database using:

sudo rm /var/db/volinfo.database

Use vsdbutil to set it for a path instead of a physical drive:

vsdbutil -a /Volume/Diskname

Although the man page suggests it is deprecated, the man page for diskutil still refers to it and the mechanism appears to be based on Volume UUIDs not on physical disk/slice ids.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top