【问题标题】:Vagrant: how to disable NFS sync folders for Windows host?Vagrant:如何禁用 Windows 主机的 NFS 同步文件夹?
【发布时间】:2013-08-26 07:38:53
【问题描述】:

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

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

【问题讨论】:

    标签: windows vagrant nfs


    【解决方案1】:

    流浪者 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

    好吧,既然 Vagrantfile 只是一个 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?(现在手头并不方便......) .

    【讨论】:

    • 进行这种 Windows 检测的一种更简单的方法(我已经对此进行了测试)是将您的 config.vm.share_folder 行更改为以下内容:config.vm.share_folder("vagrant-root", "/vagrant", "../..", :nfs => !RUBY_PLATFORM.downcase.include?("w32"))
    • 很高兴为您提供帮助,@anon58192932!
    猜你喜欢
    • 2016-01-08
    • 1970-01-01
    • 2014-12-29
    • 2015-09-26
    • 2016-04-25
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多