16

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

17

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
  • 2
    This isn't completely accurate - diskutil is going to tell you that you need to specify a disk with a mount point, meaning that you have to point it to the slice for the volume you want to rename. The correct syntax (assuming slice 2 of disk 2) would be: sudo diskutil enableOwnership /dev/disk2s2 If you run: sudo diskutil list you'll be able to see all the disk information, and find the correct disk & slice for your volume. – user27585 Aug 17 '12 at 13:14
  • I have found that I must re-invoke diskutil enableOwnership between mounts, or else I cannot execute binaries and scripts on the mounted volume. – psoft Oct 24 '12 at 19:31
5

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
  • can you give an example, I did not get what should I write in the place of s<slicenum> – Sun Sep 30 '17 at 10:50
2

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.

You must log in to answer this question.

protected by Community Aug 11 '18 at 18:55

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .