28 C
Thursday, June 24, 2021

Vagrant Up Hangs When Mounting NFS Shared Folders – How To Fix?

Must read

Today I created a new Virtual machine with Arch Linux vagrant box. I started the Arch Linux virtual machine with vagrant up command, but it didn’t start. Every time I try to start the VM, the vagrant up hangs when mounting NFS shared folders. After waiting more than 5 minutes, the command ended with the following error:

 ==> default: Mounting NFS shared folders…
 ==> default: Pruning invalid NFS exports. Administrator privileges will be required…
 [sudo] password for sk: 
 ==> default: Removing domain…
 The following SSH command responded with a non-zero exit status.
 Vagrant assumes that this means the command failed!
 mount -o vers=3,udp /vagrant
 Stdout from the command:
 Stderr from the command:
 mount.nfs: Connection refused
Vagrant up hangs when mounting NFS shared folders

As you can see, the vagrant up command fails on mounting NFS shared folders. My KVM host is latest Fedora 34 edition. I never had this issue with Ubuntu virtual machines. This error occurred only when I start Arch Linux virtual machine. If your Vagrant machine stuck while “Mounting NFS shared folders”, you can use the workaround given below.

Vagrant up hangs when mounting NFS shared folders in Linux

This is probably and more likely caused by your firewall. In my case, it is indeed the firewall issue. I had to allow the following services through the firewall to fix mounting NFS shared folders issue in Vagrant:

Also, I opened the port 2049 for both tcp and udp.

1. Run the following commands one by one to allow the aforementioned services and the port 2049.

$ sudo firewall-cmd --permanent --zone=libvirt --add-service=nfs3
$ sudo firewall-cmd --permanent --zone=libvirt --add-service=nfs
$ sudo firewall-cmd --permanent --zone=libvirt --add-service=mountd
$ sudo firewall-cmd --permanent --zone=libvirt --add-service=rpc-bind
$ sudo firewall-cmd --permanent --zone=libvirt --add-port=2049/tcp
$ sudo firewall-cmd --permanent --zone=libvirt --add-port=2049/udp

2. Reload the firewall rules to take effect the changes:

$ sudo firewall-cmd --reload

3. View the list of allowed services using command:

$ firewall-cmd --list-all

Sample output:

FedoraWorkstation (active)
  target: default
  icmp-block-inversion: no
  interfaces: wlp9s0
  services: dhcpv6-client mdns mountd nfs rpc-bind samba-client ssh
  ports: 1025-65535/udp 1025-65535/tcp
  forward: no
  masquerade: no
  rich rules: 

This enables NFS between your host and the Vagrant virtual machines and allows the libvirt hosted Vagrant VMs to use nfs mounts from the host system.

4. After allowing the nfs service and relevant port, I tried to start the Vagrant VM. This time I ran into another issue:

mount.nfs: requested NFS version or transport protocol is not supported

5. To fix this error, edit /etc/nfs.conf file in the host system:

$ sudo vi /etc/nfs.conf

6. Uncomment the following two lines:


Save the file and close it.

7. Restart the nfs service:

$ sudo systemctl restart nfs-server.service

8. Finally, reboot the host system:

$ sudo reboot

That’s it. Now you should be able to start the Vagrant machine without any issues.

We have posted a complete guide about Vagrant usage. Check following link to learn how to use Vagrant.

Source link

- Advertisement -

More articles


Please enter your comment!
Please enter your name here

- Advertisement -

Latest article