我们需要与Linux、MacOS和Windows主机共享虚拟机。但是,对于Linux和MacOS,建议使用NFS共享,但对于Windows,不支持NFS共享。
有没有办法检测主机操作系统是Windows并禁用NFS共享?
流浪者1.2.5
实际上,从Vagrant 1.2.5开始,这一点就已经得到了解决,请参阅windows主机上的NFS选项未被静默忽略,以及相应的提交b2d1a26(windows上的NFS请求被静默忽略):
@__synced_folders.each do |id, options|
# Ignore NFS on Windows
if options[:nfs] && Vagrant::Util::Platform.windows?
options[:nfs] = false
end
end
上一个解决方案
如果你无法升级,你可能想试试Ryan Seekely的Vagrant,只在非Windows主机上使用NFS:
既然Vagrantfile只不过是一个Ruby脚本,我们可以使用Ruby!在Vagrantfile的顶部定义:
def Kernel.is_windows? # Detect if we are running on Windows processor, platform, *rest = RUBY_PLATFORM.split("-") platform == 'mingw32' end
然后在配置共享文件夹时:
nfs = !Kernel.is_windows? config.vm.share_folder "myfolder", "/srv/www/myfolder.com/", "../", :nfs => nfs
请注意,我还没有真正测试过这个特定的解决方案,但我以前一直在使用概念上类似的方法,尽管在正式提交中使用Vagrant::Util::Platform.windows?
(现在还不方便…)。