Skip to content

Instantly share code, notes, and snippets.

@fnordfish
Created October 15, 2012 17:07
Show Gist options
  • Save fnordfish/3893662 to your computer and use it in GitHub Desktop.
Save fnordfish/3893662 to your computer and use it in GitHub Desktop.
Automounting Vagrant boxes in Mac OS 10.8

(Inspired by http://yourmacguy.wordpress.com/2012/06/29/osx-automount/)

Preface:

  • I have a lot of vagrant projects
  • Each of them provides an NFS-Server exporting /home/vagrant
  • Since Mac OS 10.8 the handy "NFS Mounts" from Disk Util are gone
  • I'd like a single place, in which I could copy'n'paste a config for a new box and/or comment a box (when I don't need it for some time)
  • I'd like to make this a vagrant plugin
  • Ideally, the mount will be activated/deactivated when starting/suspending a box

using "automount" and "auto_master"

  1. Edit your /etc/auto_master file and add: /Users/<your_user_name>/mounts /Users/<your_user_name/etc/automounts
  2. Create an empty directory /Users/<your_user_name>/mounts and file /Users/<your_user_name/etc/automounts
  3. For a box create an entry like this in your automounts file:
    project_x -fstype=nfs,nosuid,browse,bg,intr,soft,nonegnamecache,deadtimeout=1 33.33.33.33:/home/vagrant
    This will configure a soft, background nfs-mount of 33.33.33.33:/home/vagrant on /Users/<your_user_name>/mounts/project_x
  4. Invoke sudo automount -vc to reload (and activate) autoload config

Pros:

  • Can pass all mount options (such as soft which helps Finder not to hang when the box is hanging/reloading...)
  • Can tell where to mount things

Cons:

  • automount is a performance killer
  • Each change (adding, removing a mount point) requires a sudo which somehow eliminates the possibility to use it as a middleware

using applescript

AppleScript allows users to "Connect to Server" (pretty much the same thing as invoking cmd-K in Finder). This script will mount the same share as above on /Volumes/vagrant .

osascript -e 'try
	mount volume "nfs://33.33.33.33/home/vagrant"
end try'

Pro:

  • Does not need sudo -> can be used as automated mount/unmount

Cons:

  • Cannot pass any options
  • slows down vagrant up when the box has not (yet) started it's nfs-server or has hiccups (suspend while changing networks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment