/ vagrant

Vagrant synced folders failed

Vagrant 选择 virtualbox 作为 provider 时,会默认使用 VirtualBox shared folders 作为同步文件夹的工具,但是最近遇到了一个大坑:无法在 host 里挂在共享文件下,然后把 virtualbox 从4.3.14降到4.2.24,然后又把 ubuntu 从12.04 换到 14.04 结果还是出现这个问题。

vagrant up时,会出现下面的错误

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

然后网上的解决办法我都试过了,结果还是不行,然后我就试了一下

mount.vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant

结果挂载上了
但是每次启动时,还是不能自动挂载上,因为这段挂载是写在 vagrant 里的。

最终解决办法:使用RSync替代

config.vm.synced_folder ".", "/vagrant", type: "rsync"

Update: 最终决绝办法
~~Vagrantfile 里加入

  config.vm.synced_folder ".", "/vagrant", disabled: true
```~~
上述方法无效,`disabled: true`会禁用掉同步功能,仅仅只是把 host 的共享文件复制了一份

还是需要加入

config.vm.synced_folder ".", "/home/vagrant/src"
config.vm.synced_folder "~", "/vagrant", disabled: true
config.vm.provider :virtualbox do |vb|
#vb.customize [ "modifyvm", :id, "--memory", 2048 ]
vb.customize [ "modifyvm", :id, "--natdnshostresolver1", "on" ]
vb.customize [ "setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-src", "1"]
end

来自:http://segmentfault.com/q/1010000000649349#a-1020000000649773