hashicorp / hashicorp/vagrant

Stuck at default: Mounting NFS shared folders... mount.nfs: Connection timed out the 1001th issue

Open
#12,596 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
27.2k
Forks
4.4k
Avg merge
1m
Merged PRs (30d)
1

Description

```
=> default: Mounting NFS shared folders...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mount -o vers=3,udp,vers=4,tcp 192.168.50.1:/u/w/n.com /vagrant-nfs-n.com

Stdout from the command:

Stderr from the command:

mount.nfs: Connection timed out
```

This really is getting annoying. This and similar issues go back to 2015 or even b4, I have seen this happening on all OSes in different variations. This seems to be a total mess and it not getting better. I already spent many hours of tine trying to fix this and the last thing I remembered I did was adding `mount_options: ["vers=4,tcp"]` to my Vagrantfile and I think this was what fixed it, I have added and tried many other things. The VAST amount of issues around this and solutions are crazy, ranging from adding rules to firewalls ... all kinds of things. I had the same issue b4 with a different solution I think.

Can this he solved ONCE AND FOR ALL? Maybe? How about building in some tests in the actual exaction of Vagrant? Like going down the list of fixes and solutions and checking if they are applied to the system, like firewall rules of whatever. And if system needs and supports version 4 use it with TCP by default? From what I remember, in THEORY version 3 should still work on the latest cutting-edge stuff Tumbleweed ships with, but for me that is what fixed it I think - until now.

How about putting out some actual helpful error messages like the "if vagrant was recently updated, do this". That I have to run after every update, it's annoying, but at least it points me to the solution that actually works.

I noticed this

`mount -o vers=3,udp,vers=4,tcp 192.168.50.1:/u/w/n.com /vagrant-nfs-n.com` it seems the options get put at the end, but there are also the WRONG options on the beginning of the command. My guess is that mount uses the options that come first. So my custom options are not used anymore since last version. That is my guess is what happens.

### Vagrant version

Vagrant 2.2.18

### Host operating system

Open SUSE Tumbleweed

### Guest operating system

Ubuntu 20.10

### Vagrantfile

```ruby
ANSIBLE_PATH = __dir__ # absolute path to Ansible directory on host machine
ANSIBLE_PATH_ON_VM = '/home/vagrant/trellis'.freeze # absolute path to Ansible directory on virtual machine

require File.join(ANSIBLE_PATH, 'lib', 'trellis', 'vagrant')
require File.join(ANSIBLE_PATH, 'lib', 'trellis', 'config')
require 'yaml'

vconfig = YAML.load_file("#{ANSIBLE_PATH}/vagrant.default.yml")

if File.exist?("#{ANSIBLE_PATH}/vagrant.local.yml")
local_config = YAML.load_file("#{ANSIBLE_PATH}/vagrant.local.yml")
vconfig.merge!(local_config) if local_config
end

ensure_plugins(vconfig.fetch('vagrant_plugins')) if vconfig.fetch('vagrant_install_plugins')

trellis_config = Trellis::Config.new(root_path: ANSIBLE_PATH)

Vagrant.require_version '>= 2.1.0'

Vagrant.configure('2') do |config|

# NICO
config.vm.network "public_network"

config.vm.box = vconfig.fetch('vagrant_box')
config.vm.box_version = vconfig.fetch('vagrant_box_version')
config.ssh.forward_agent = true
config.vm.post_up_message = post_up_message

# Fix for: "stdin: is not a tty"
# https://github.com/mitchellh/vagrant/issues/1673#issuecomment-28288042
config.ssh.shell = %(bash -c 'BASH_ENV=/etc/profile exec bash')

# Required for NFS to work
if vconfig.fetch('vagrant_ip') == 'dhcp'
config.vm.network :private_network, type: 'dhcp', hostsupdater: 'skip'

cached_addresses = {}
config.hostmanager.ip_resolver = proc do |vm|
if cached_addresses[vm.name].nil?
if vm.communicate.ready?
vm.communicate.execute("hostname -I | cut -d ' ' -f 2") do |_type, contents|
cached_addresses[vm.name] = contents.split("\n").first[/(\d+\.\d+\.\d+\.\d+)/, 1]
end
end
end
cached_addresses[vm.name]
end
else
config.vm.network :private_network, ip: vconfig.fetch('vagrant_ip'), hostsupdater: 'skip'
end

main_hostname, *hostnames = trellis_config.site_hosts_canonical
config.vm.hostname = main_hostname

if Vagrant.has_plugin?('vagrant-hostmanager') && !trellis_config.multisite_subdomains?
redirects = trellis_config.site_hosts_redirects

config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.aliases = hostnames + redirects
elsif Vagrant.has_plugin?('landrush') && trellis_config.multisite_subdomains?
config.landrush.enabled = true
config.landrush.tld = trellis_config.site_hosts_canonical.reject { |host| host.end_with?(".#{main_hostname}") }
hostnames.each { |host| config.landrush.host host, vconfig.fetch('vagrant_ip') }
else
fail_with_message "vagrant-hostmanager missing, please install the plugin with this command:\nvagrant plugin install vagrant-hostmanager\n\nOr install landrush for multisite subdomains:\nvagrant plugin install landrush"
end

bin_path = File.join(ANSIBLE_PATH_ON_VM, 'bin')

vagrant_mount_type = vconfig.fetch('vagrant_mount_type')

extra_options = if vagrant_mount_type == 'smb'
{
smb_username: vconfig.fetch('vagrant_smb_username', nil),
smb_password: vconfig.fetch('vagrant_smb_password', nil),
}
else
{}
end

if vagrant_mount_type != 'nfs' || Vagrant::Util::Platform.wsl? || (Vagrant::Util::Platform.windows? && !Vagrant.has_plugin?('vagrant-winnfsd'))
vagrant_mount_type = nil if vagrant_mount_type == 'nfs'
trellis_config.wordpress_sites.each_pair do |name, site|
config.vm.synced_folder local_site_path(site), remote_site_path(name, site), owner: 'vagrant', group: 'www-data', mount_options: mount_options(vagrant_mount_type, dmode: 776, fmode: 775), type: vagrant_mount_type, **extra_options
end

config.vm.synced_folder ANSIBLE_PATH, ANSIBLE_PATH_ON_VM, mount_options: mount_options(vagrant_mount_type, dmode: 755, fmode: 644), type: vagrant_mount_type, **extra_options
config.vm.synced_folder File.join(ANSIBLE_PATH, 'bin'), bin_path, mount_options: mount_options(vagrant_mount_type, dmode: 755, fmode: 755), type: vagrant_mount_type, **extra_options
elsif !Vagrant.has_plugin?('vagrant-bindfs')
fail_with_message "vagrant-bindfs missing, please install the plugin with this command:\nvagrant plugin install vagrant-bindfs"
else
trellis_config.wordpress_sites.each_pair do |name, site|
config.vm.synced_folder local_site_path(site), nfs_path(name), type: 'nfs', mount_options: ["vers=4,tcp"]
config.bindfs.bind_folder nfs_path(name), remote_site_path(name, site), u: 'vagrant', g: 'www-data', o: 'nonempty'
end

config.vm.synced_folder ANSIBLE_PATH, '/ansible-nfs', type: 'nfs', mount_options: ["vers=4,tcp"]
config.bindfs.bind_folder '/ansible-nfs', ANSIBLE_PATH_ON_VM, o: 'nonempty', p: '0644,a+D'
config.bindfs.bind_folder bin_path, bin_path, perms: '0755'
end

vconfig.fetch('vagrant_synced_folders', []).each do |folder|
options = {
type: folder.fetch('type', 'nfs'),
create: folder.fetch('create', false),
mount_options: folder.fetch('mount_options', [])
}

destination_folder = folder.fetch('bindfs', true) ? nfs_path(folder['destination']) : folder['destination']

config.vm.synced_folder folder['local_path'], destination_folder, options

if folder.fetch('bindfs', true)
config.bindfs.bind_folder destination_folder, folder['destination'], folder.fetch('bindfs_options', {})
end
end

provisioner = local_provisioning? ? :ansible_local : :ansible
provisioning_path = local_provisioning? ? ANSIBLE_PATH_ON_VM : ANSIBLE_PATH

config.vm.provision provisioner do |ansible|
if local_provisioning?
ansible.extra_vars = { ansible_python_interpreter: vconfig.fetch('vagrant_ansible_python_interpreter') }
ansible.install_mode = 'pip'
ansible.pip_install_cmd = 'sudo apt-get install -y -qq python3-distutils && curl https://bootstrap.pypa.io/get-pip.py | sudo python3'
ansible.provisioning_path = provisioning_path
ansible.version = vconfig.fetch('vagrant_ansible_version')
end

ansible.compatibility_mode = '2.0'
ansible.playbook = File.join(provisioning_path, 'dev.yml')
ansible.galaxy_role_file = File.join(provisioning_path, 'galaxy.yml') unless vconfig.fetch('vagrant_skip_galaxy') || ENV['SKIP_GALAXY']
ansible.galaxy_roles_path = File.join(provisioning_path, 'vendor/roles')

ansible.groups = {
'web' => ['default'],
'development' => ['default']
}

ansible.tags = ENV['ANSIBLE_TAGS']
ansible.extra_vars = { 'vagrant_version' => Vagrant::VERSION }

if (vars = ENV['ANSIBLE_VARS'])
extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }]
ansible.extra_vars.merge!(extra_vars)
end

if !Vagrant::Util::Platform.windows?
config.trigger.after :up do |trigger|
# Add Vagrant ssh-config to ~/.ssh/config
trigger.info = "Adding vagrant ssh-config for #{main_hostname } to ~/.ssh/config"
trigger.ruby do
update_ssh_config(main_hostname)
end
end
end
end

# VirtualBox settings
config.vm.provider 'virtualbox' do |vb|
vb.name = config.vm.hostname
vb.customize ['modifyvm', :id, '--cpus', vconfig.fetch('vagrant_cpus')]
vb.customize ['modifyvm', :id, '--memory', vconfig.fetch('vagrant_memory')]
vb.customize ['modifyvm', :id, '--ioapic', vconfig.fetch('vagrant_ioapic', 'on')]

# Fix for slow external network connections
# Commenting out below DOES NOT FIX Stuck at 'SSH auth method: private key'
vb.customize ['modifyvm', :id, '--natdnshostresolver1', vconfig.fetch('vagrant_natdnshostresolver', 'on')]
vb.customize ['modifyvm', :id, '--natdnsproxy1', vconfig.fetch('vagrant_natdnsproxy', 'on')]

# DOES NOT FIX Stuck at 'SSH auth method: private key' https://github.com/hashicorp/vagrant/issues/11777#issuecomment-661076612 ...
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]

# some if the below fixes Stuck at 'SSH auth method: private key'
vb.memory = "2048"

vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
vb.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL]

vb.customize ["modifyvm", :id, "--nestedpaging", "off"]
vb.customize ["modifyvm", :id, "--cpus", 4]
vb.customize ["modifyvm", :id, "--paravirtprovider", "hyperv"]
end

# VMware Workstation/Fusion settings
%w(vmware_fusion vmware_workstation).each do |provider|
config.vm.provider provider do |vmw|
vmw.vmx['displayName'] = config.vm.hostname
vmw.vmx['numvcpus'] = vconfig.fetch('vagrant_cpus')
vmw.vmx['memsize'] = vconfig.fetch('vagrant_memory')
end
end

# Parallels settings
config.vm.provider 'parallels' do |prl|
prl.name = config.vm.hostname
prl.cpus = vconfig.fetch('vagrant_cpus')
prl.memory = vconfig.fetch('vagrant_memory')
prl.update_guest_tools = true
end

# Hyper-V settings
config.vm.provider 'hyperv' do |h|
h.vmname = config.vm.hostname
h.cpus = vconfig.fetch('vagrant_cpus')
h.memory = vconfig.fetch('vagrant_memory')
h.enable_virtualization_extensions = true
h.linked_clone = true
end
end
```

### Debug output

### Expected behavior

Just work, or at least put out error messages about what to do.

### Actual behavior

Timeout AGAIN.

### Steps to reproduce

1. vagrant up

### References

Countless issues about this for many many years, more or less arround the same issue(s), even saw one on Windows 10 today about something related.

Contributor guide

Open the contributing guide

Research direction

Start with the Vagrantfile's synced_folder configuration and the generated NFS mount command, especially the ordering of mount_options. Reproduce with `vagrant up` and inspect how the NFS options are assembled; done would require a reliable mount or a specific, actionable error for the reported timeout cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
devops, infrastructure
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.