Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NFS Fails after packaging a Vagrant box

I'm facing an odd problem with (re)packaging a Vagrant box and hope that maybe someone can tell me in what direction to look. This is the story

  • I installed Vagrant and have successfully created some puppet manifests and it all works fine, vagrant up ... provisioning, ...
  • Then I needed to switch to NFS which failed because nfs was not installed on my Guest OS (Ubuntu 11.04-amd64)
  • I installed nfs-common on the guest OS (sudo apt-get install nfs-common)
  • vagrant halt
  • vagrant up
  • And the NFS mount works flawlessly, even after several halt/up commands, I'm happy!

The next logical step would be packaging the box so I do not need to reinstall nfs-common each time the VM is destroyed.

  • In the same directory as above : vagrant package
  • vagrant box add ubuntuvm2 package.box
  • rm package.box
  • change the line config.vm.box in Vagrantfile to ubuntuvm2
  • vagrant destroy
  • vagrant up
  • and all of a sudden the nfs mount fails, when sshing into the VM i can confirm that nfs-common is indeed installed but the NFS mount just fails: https://img.skitch.com/20120302-kwix296t44y31rxkd52pwm72f4.jpg

Anyone has an idea in what direction to start looking for a solution?

I'm using Virtualbox 4.1.8 and Vagrant 1.0.0 on OS-X Lion

like image 402
ChrisR Avatar asked Mar 14 '12 08:03

ChrisR


2 Answers

I had the very same problem, but I have figured it out. At least it works for me now. :)

TL;DR:

  • Check /etc/exports for syntax errors and recreate /etc/exports with an entry you make sure works.
  • Verify network interfaces on the box are initialized correctly (check /etc/network/interfaces and run ifconfig -a).
  • At least Debian and Ubuntu store information about the persistent network device in /etc/udev/rules.d/70-persistent-net.rules. If you see that eth1 is initialized as eth2 it is because the mac adress of the network card is regenerated when you create a new box instance. rm /etc/udev/rules.d/70-persistent-net.rules and repackage your box.
  • If you are unable to repackage your box update /etc/network/interfaces to use eth2 instad of eth1

Long form:

  • Vagrant is 1.0.1
  • OS X is 10.7.3
  • Box is custom Debian Wheezy 64.

When reloading or recreating the box it would die on NFS mount with the typical message.

[default] Mounting NFS shared folders...
Mounting NFS shared folders failed. This is most often caused by the NFS
client software not being installed on the guest machine. Please verify
that the NFS client software is properly installed, and consult any resources
specific to the linux distro you're using for more information on how to
do this.

Inspecting the /etc/exports file with NFS Manager it tells me my /etc/exports contain syntax errors.

I clean out /etc/exports and test nfs client and server with this entry:

/Users/tm/git -alldirs localhost 33.33.33.10

When running vagrant up NFS mounting is working again.

When repackaging box after apt-get dist-upgrade I noticed the NFS folders would not mount again.

This time there were no errors in the /etc/exports file. I discovered Vagrant had not initialized the host local interface.

/etc/network/interfaces contained this:

#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
    address 33.33.33.10
    netmask 255.255.255.0
#VAGRANT-END

ifconfig -a returned this:

eth0      Link encap:Ethernet  HWaddr 08:00:27:3a:47:72  
      inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
      inet6 addr: fe80::a00:27ff:fe3a:4772/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:971 errors:0 dropped:0 overruns:0 frame:0
      TX packets:614 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:83951 (81.9 KiB)  TX bytes:74872 (73.1 KiB)

eth2      Link encap:Ethernet  HWaddr 08:00:27:89:f5:e3  
      BROADCAST MULTICAST  MTU:1500  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

The interface was not defined correctly. After updating the /etc/network/intefaces stanza to use eth2 NFS mounting is working again.

like image 69
thomasmalt Avatar answered Sep 22 '22 00:09

thomasmalt


Here is an open bug about this and a solution:

https://github.com/mitchellh/vagrant/issues/997

  1. edit /etc/udev/rules.d/70-persistent-net.rules and delete lines for interfaces other than eth0
  2. vagrant package
  3. vagrant box add mypack package.box
  4. vagrant destroy
  5. In Vagrantfile set config.vm.box to mypack
  6. vagrant up

I tested this on MAC OS X 10.7.5 and CentOS 6.2 64bit

UPDATE: the bug is now closed and moved but it looks like folks are still having the problem.

like image 41
Steve Tauber Avatar answered Sep 23 '22 00:09

Steve Tauber