Vagrant synced folder options
Asked Answered
G

2

7

What is the best method for implementing Vagrant NFS "synced folders" between host and VM?

I was finally able to get NFS working, in general, but it required several tweaks within the VM; and I'm not sure how to automate those changes for others to use.

Specifically, I have to modify the UID/GID in /etc/passwd and /etc/group to match those of the user/group of the exported filesystem. (e.g. host machine uses 502:20, VM apache user must be set to use 502:20 as well)

Without this change, I have all kinds of permission/ownership issues that prevent the web app from running. With the UID/GID matching, everything works great.

I've read all the docs I could find, including the Vagrant web site.

As a side note: I also tried native folder sync (painfully slow) and rsync (100% CPU... unusable)

NFS seems like the winner for performance, but my setup is sketchy.

If it makes any difference, I'm working with the following:

  • Host: OS X 10.9.2
  • Vagrant: 1.5.4
  • Provider: VMware Fusion
  • Box: chef/centos-6.5
  • Dev app: Magento 1.8
Glialentn answered 22/5, 2014 at 5:31 Comment(1)
Thanks, I was having the same issues with NFS but I had not got as far as you be fixing it manually. Between your question and sschoen's answer I now have it all sorted.Fonteyn
M
12

In Vagrantfile you can assign the current uid/gid to the nfs mapping. (See on host /etc/exports after provisioning.)

 config.nfs.map_uid = Process.uid   
 config.nfs.map_gid = Process.gid 

With Puppet as provisioner you can facter these values:

 config.vm.provision :puppet, :facter => { 
     "host_uid" => config.nfs.map_uid, 
     "host_gid" => config.nfs.map_gid, 
 } do |puppet| ...

So you can use it in puppet scope like variables e.g.

user { "www-data":
    ensure => present,
    uid => $::host_uid,
    gid => $::host_gid,
}

I think in chef the custom json option is the equivalent to use it later in chef recipes

Vagrant.configure("2") do |config|
  config.vm.provision "chef_solo" do |chef|
        # ...

        chef.json = {
          "map" => {
            "uid" => config.nfs.map_uid,
            "gid" => config.nfs.map_gid
          }
        }
      end
    end
Manifold answered 27/5, 2014 at 10:44 Comment(1)
Thanks, if I could give this more than one upvote I would, it really helped me out.Fonteyn
C
5

bindfs

GitLab was using bindfs before it deprecated Vagrant as development method.

There is even a Vagrant plugin for it at: https://github.com/gael-ian/vagrant-bindfs

Relevant Vagrantfile lines when the file was still part of the project:

config.vm.synced_folder ".", "/vagrant", :disabled => true
config.vm.synced_folder "./home_git", "/git-nfs", :nfs => true
config.bindfs.bind_folder "/git-nfs", "/home/git", :owner => "1111", :group => "1111", :'create-as-user' => true, :perms => "u=rwx:g=rwx:o=rwx", :'create-with-perms' => "u=rwx:g=rwx:o=rwx", :'chown-ignore' => true, :'chgrp-ignore' => true, :'chmod-ignore' => true
Communicable answered 24/5, 2014 at 7:4 Comment(2)
Beware bindfs performance penalty: redbottledesign.com/blog/…. This has kept me looking for alternate solutions ;)Talos
@SamT that link is dead.Tizes

© 2022 - 2024 — McMap. All rights reserved.