4

We need to share VMs with Linux, MacOS and Windows hosts. However, for Linux and MacOS, NFS sharing is recommended, but for Windows, NFS sharing is not supported.

Is there are way to detect the that host OS is Windows and disable NFS shares?

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
Andrew
  • 1,226
  • 2
  • 13
  • 20

1 Answers1

6

Vagrant 1.2.5

This has actually already been taking care of as of Vagrant 1.2.5, see Option for NFS is not silently ignored on windows hosts and the respective commit 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

Previous Workaround

If you aren't able to upgrade you might want to try Ryan Seekely's 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

Please note that I haven't actually tested this particular solution, but have been using a conceptually similar approach myself before, albeit using Vagrant::Util::Platform.windows? as in the official commit (don't have it handy right now ...).

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
  • 1
    A simpler way to do this sort of Windows detection (I have tested this) is to change your `config.vm.share_folder` line to read something like this: `config.vm.share_folder("vagrant-root", "/vagrant", "../..", :nfs => !RUBY_PLATFORM.downcase.include?("w32"))` – Sam Dec 18 '14 at 09:51
  • Glad to help, @anon58192932! – Sam Oct 04 '16 at 07:24