Vagrant hangs after using command vagrant up on Mounting NFS shared folders
2.2.9
MacOS Catalina 10.15.6
Red Hat 64bit
# coding: utf-8
require 'fileutils'
# Module to check for OS version. Vagrant shared folder config will vary depending on the OS.
# Windows users will have to make due with rsync.
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.windows?
end
def OS.linux?
OS.unix? and not OS.mac?
end
end
# Make sure we have vagrant-vbguest installed
if !Vagrant.has_plugin?('vagrant-vbguest')
puts 'vagrant-vbguest plugin required. Run `vagrant plugin install vagrant-vbguest` to install'
abort
end
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.provider "virtualbox" do |v|
v.cpus = 4
v.memory = 4048
v.customize ["modifyvm", :id, "--audio", "none"]
end
is_windows_host = "#{OS.windows?}"
puts "is_windows_host: #{OS.windows?}"
if OS.windows?
# puts "Vagrant launched from windows. Using rsync for shared folder."
# config.vm.synced_folder '.', '/vagrant', type: "rsync", rsync__auto: true
puts "Vagrant launched from windows. Using NFS for shared folder."
config.vm.synced_folder '.', '/vagrant', nfs: true, type: "nfs", nfs_export: false
else
puts "Vagrant launched from *nix, using NFS for shared folder."
config.vm.synced_folder '.', '/vagrant', nfs: true
end
config.vm.synced_folder nfsPath, "/vagrant", type: "nfs"
end
# Use NFS for shared folders for better performance
config.vm.network "private_network", ip: "192.168.99.50"
# Forwarde port 8080 for Tomcat og 8000 for remote debugging
config.vm.network "forwarded_port", guest: 8090, host: 8090 # Tomcat HTTP
config.vm.network "forwarded_port", guest: 5005, host: 5005 # Java Debug
# Execute provision script
config.vm.provision :shell, :path => "vagrant/bootstrap.sh"
config.vm.provision "file", source: "vagrant/.bashrc", destination: "~/.bashrc"
config.vm.provision "shell", privileged: true, inline: "timedatectl set-timezone Europe/Oslo"
ssh_key_path = ENV['SSH_KEY'] || File.join(Dir.home, ".ssh", "id_rsa")
if File.exist?(ssh_key_path)
ssh_key = IO.read(ssh_key_path)
else
raise Vagrant::Errors::VagrantError.new, "Key missing #{ssh_key_path}, set SSH_KEY=/path/to/ssh/key, or comment out this feature."
end
config.vm.provision :shell, :inline => "echo 'Windows-specific: Copying a local SSH Key to VM for provisioning...' && mkdir -p /home/vagrant/.ssh && echo '#{ssh_key}' > /home/vagrant/.ssh/id_rsa && chmod 600 /home/vagrant/.ssh/id_rsa && chown vagrant:vagrant /home/vagrant/.ssh/id_rsa"
end
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o vers=3,udp 192.168.99.1:/System/Volumes/Data/Users/USERNAME/src/project /vagrant
Stdout from the command:
Stderr from the command:
mount.nfs: Connection timed out
It should share NFS folder
hangs on: default: Mounting NFS shared folders...
vagrant up
From the connection time out error, it seems like the nfs server is not running or the export is not happening successfully. You could check for if the mount is available using the command showmount -e <ip>. If the export does not appear to be available on the guest and host, check if the nfs server is running using ps aux | grep nfsd on the host. Further, ensure that the folder being exported is included in /etc/exports. This file can be verified using the command nfsd checkexports.
folder is included in /etc/exports,
"showmount -e" prints out correct folder however "nfsd checkexports" does and returns nothing.
showmount -e ip returns correct path and target ip
hmmm, it seems like nfs it probably all in order. Another thing that might be causing issues is firewalls including iptables. Can you verify that the ports required for nfs are not being blocked on the guest. I believe they are 111 and 2049.
Firewall was off and encryption was off.
If this is still an issue for you, please check out the Vagrant guide for troubleshooring NFS issues here:
https://www.vagrantup.com/docs/synced-folders/nfs.html#troubleshooting-nfs-issues. It covers the most common hiccups in setting up NFS with Vagrant.
Did you get anywhere with this please @FugueDev ? I'm having the same issue.
No, sorry. Tried everything. Works flawlessly on linux or windows.
I had the exact same issue as @FugueDev, and now something that I've tried has made it work. I'm not entirely sure if all of them mattered, but these are the changes I've made:
/sbin/nfsd on my Mac, as suggested in this articlesubconfig.vm.synced_folder ".", "/vagrant", type: "nfs"nfsPath = "."
if Dir.exist?("/System/Volumes/Data")
nfsPath = "/System/Volumes/Data" + Dir.pwd
end
subconfig.vm.synced_folder nfsPath, "/vagrant", type: "nfs"
/etc/exports on my Mac, and restarted the nfs daemon sudo nfsd restartvagrant upafter these steps, the error went away. I still somehow had to ssh into the vagrant box and perform the mount command on my first successful attempt. not sure why though.
Hope it helps.
It appears that vagrant is prefixing /System/Volumes/Data to its entries in /etc/exports. This causes mounts to fail. I had to replicate the lines myself without the prefix and then things started working.
@tmm1 I've had no luck with trimming that off them, and that is something that Catalina brought in. https://github.com/hashicorp/vagrant/issues/10961
It appears that vagrant is prefixing
/System/Volumes/Datato its entries in/etc/exports. This causes mounts to fail. I had to replicate the lines myself without the prefix and then things started working.
@tmm1 How did you remove the line? It seems that vagrant is adding /System/Volumes/Data on reload.
My solution is to edit the file, replicate the line without the vagrant comments and remove the prefix. That works for me.
FYI the problem persist in Big Sur
Most helpful comment
FYI the problem persist in Big Sur