Vagrant: Add documentation for mount_options with examples

Created on 26 Sep 2013  ยท  10Comments  ยท  Source: hashicorp/vagrant

I ran into a vagrant file that used the deprecated "extra" flag to set a shared folder options instead of "mount_options." Unfortunately, I could not find clear documentation of how to set up the array for mount_options in issue #1029 or in the documentation. So requesting documentation with examples of using mount_options. Thanks.

documentation

Most helpful comment

Mount options are still not very clearly defined or examples given. https://www.vagrantup.com/docs/synced-folders/basic_usage.html says mount_options (array) - A list of additional mount options to pass to the mount command. but no where that I can find are those additional mount options defined.

All 10 comments

From my own testing:

# Deprecated
# config.vm.share_folder "ckan", "/home/vagrant/chef", "..", :create => true, :extra => "dmode=755,fmode=755"

# Working mount_option version
config.vm.share_folder "ckan", "/home/vagrant/chef", "..", :create => true, :mount_options => ["dmode=755","fmode=755"]

Thanks. I've tagged this as a doc issue.

I'd like to see this mount_options documentation issue addressed before I suggest rolling-out an upgrade of vagrant from v1.1.2 to 1.2.x in our development team.

Is there some way that we can contribute to the docs, so that issues like this can be resolved by the community writing documentation?

FWIW, we wanted to sync a web directory folder AND set folder ownership to the apache group, but Vagrant wanted to control the ownership of the directory.

Why do we want to do this?

  1. Vagrant rocks to spin up environments.
  2. GitMachines are VMs pre-configured for government security and compliance requirements -- so we need to control the ownership and permissions of the web directories on the VM.
  3. We want the VM web application code also easily accessible on the host machine for review and development.

We, like others, found a way with mounts. But that still presents an issue of re-provisioning when re-launching a shut down vagrant box.

Excerpt from our project: https://github.com/GitMachines/statedecoded-gm-centos6

Vagrant snippet

config.vm.synced_folder "statedecoded/", "/var/www/html/statedecoded", id: "vagrant-root", create: true

Puppet snippet

# Until we figure out a better way
exec { 'mount-shared':
        command                => '/bin/umount /var/www/html/statedecoded; /bin/echo "/var/www/html/statedecoded      /var/www/html/statedecoded      vboxsf   uid=`id -u apache`,gid=`id -g apache`   0 0" >> /etc/fstab; /bin/mount /var/www/html/statedecoded',
        require                => Class['apache']
}

@gregelin
We do the same thing on our web development projects using Vagrant and Puppet. To prevent the command executing on every provision, just add an onlyif to your Puppet exec like this:

  exec { 
    "project-mount-permissions" :
      command => "umount /opt/projects/www; mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g apache`,dmode=775,fmode=664 /opt/projects/www /opt/projects/www",
      path    => ["/bin", "/usr/bin", "/usr/sbin"],
      onlyif  => "test $(stat --format=%g /opt/projects/www/) -ne $(id -g apache) -o $(stat --format=%u /opt/projects/www/) -ne $(id -u vagrant)",
      require => Package["httpd"];
  } 

With the statement above your Mount Permissions are only applied if the _owner_ isn't vagrant or the _group_ isn't apache.

@christopher-hopper Thanks!

Fixed! Thanks.

Mount options are still not very clearly defined or examples given. https://www.vagrantup.com/docs/synced-folders/basic_usage.html says mount_options (array) - A list of additional mount options to pass to the mount command. but no where that I can find are those additional mount options defined.

I could be mistaken, but I believe mount_options are options passed to the mount command on the guest.

See "Mount options for udf": http://man7.org/linux/man-pages/man8/mount.8.html

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rhencke picture rhencke  ยท  3Comments

luispabon picture luispabon  ยท  3Comments

dorinlazar picture dorinlazar  ยท  3Comments

bbaassssiiee picture bbaassssiiee  ยท  3Comments

hesco picture hesco  ยท  3Comments