【发布时间】:2013-08-26 07:38:53
【问题描述】:
我们需要与 Linux、MacOS 和 Windows 主机共享 VM。但是,对于 Linux 和 MacOS,建议使用 NFS 共享,但对于 Windows,不支持 NFS 共享。
有没有办法检测到主机操作系统是 Windows 并禁用 NFS 共享?
【问题讨论】:
我们需要与 Linux、MacOS 和 Windows 主机共享 VM。但是,对于 Linux 和 MacOS,建议使用 NFS 共享,但对于 Windows,不支持 NFS 共享。
有没有办法检测到主机操作系统是 Windows 并禁用 NFS 共享?
【问题讨论】:
这实际上已经从 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?(现在手头并不方便......) .
【讨论】:
config.vm.share_folder 行更改为以下内容:config.vm.share_folder("vagrant-root", "/vagrant", "../..", :nfs => !RUBY_PLATFORM.downcase.include?("w32"))