Skip to content

Instantly share code, notes, and snippets.

@mattghali
Last active May 22, 2017 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattghali/3922358778c8273a5d70de581c011cca to your computer and use it in GitHub Desktop.
Save mattghali/3922358778c8273a5d70de581c011cca to your computer and use it in GitHub Desktop.
Prevent OSX from automounting removable volumes

So I spent most of the mornings searching google for how to prevent Mac OSX from automounting removable volumes to no avail. The closest people seem to have come is hard-coding volume UUIDs in fstab; which presents a chicken-and-egg problem: how do you find the volume UUID to blacklist without (inadvertently) mounting it?

The answer is close by in the code to an option another people seem to be searching for frequently - how to get OSX to mount removable volumes at boot time instead of at login. The global preference key AutomountDisksWithoutUserLogin controls it, by setting several other hidden preference keys for diskarbitrationd. See the code here.

The hidden pref keys are at this line:

  • DAMountDeferExternal
  • DAMountDeferInternal
  • DAMountDeferRemovable
  • DAMountTrustExternal
  • DAMountTrustInternal
  • DAMountTrustRemovable

You can see where the global pref AutomountDisksWithoutUserLogin controls diskarbitrationd setting defaults for three of these options in this function

(TLDR) So, what I've set manually, to prevent OSX from automounting removable volumes is:

sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount.plist DAMountDeferRemovable -bool false
sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount.plist DAMountDeferExternal -bool false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment