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

4
我们需要将虚拟机与Linux、MacOS和Windows主机共享。但是,对于Linux和MacOS,建议使用NFS共享,而对于Windows,则不支持NFS共享。
有没有一种方法可以检测主机操作系统是否为Windows并禁用NFS共享?
1个回答

6

Vagrant 1.2.5

从Vagrant 1.2.5版本开始,这个问题已经得到了解决。请参考Option for NFS is not silently ignored on windows hosts和相关提交b2d1a26 (NFS request is silently ignored on Windows)

@__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 and using NFS only on non Windows hosts

Well, since a Vagrantfile is nothing but a Ruby script, we can just use Ruby! At the top of the Vagrantfile define:

def Kernel.is_windows?
    # Detect if we are running on Windows
    processor, platform, *rest = RUBY_PLATFORM.split("-")
    platform == 'mingw32'
end

And then when configuring your shared folder:

nfs = !Kernel.is_windows?
config.vm.share_folder "myfolder", "/srv/www/myfolder.com/", "../", :nfs => nfs

请注意,我实际上没有测试过这个特定的解决方案,但之前我自己使用过概念上类似的方法,只是在官方提交中使用了Vagrant::Util::Platform.windows?(现在手头没有...)。


1
一个更简单的方法来进行这种Windows检测(我已经测试过了)是将你的config.vm.share_folder行更改为类似于以下内容:config.vm.share_folder("vagrant-root", "/vagrant", "../..", :nfs => !RUBY_PLATFORM.downcase.include?("w32")) - Sam
很高兴能帮助你,@anon58192932! - Sam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接