Vagrant:如何为Windows主机禁用NFS同步文件夹?

And*_*rew 4 windows nfs vagrant

我们需要与Linux,MacOS和Windows主机共享VM.但是,对于Linux和MacOS,建议使用NFS共享,但对于Windows,不支持NFS共享.

有没有办法检测主机操作系统是Windows并禁用NFS共享?

Ste*_*pel 6

流浪汉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
Run Code Online (Sandbox Code Playgroud)

上一个解决方法

如果您无法升级,可能需要尝试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
Run Code Online (Sandbox Code Playgroud)

然后在配置共享文件夹时:

nfs = !Kernel.is_windows?
config.vm.share_folder "myfolder", "/srv/www/myfolder.com/", "../", :nfs => nfs
Run Code Online (Sandbox Code Playgroud)

请注意,我实际上没有测试过这个特定的解决方案,但之前我一直在使用一种概念上类似的方法,尽管Vagrant::Util::Platform.windows?在官方提交中使用(现在没有方便...).