VirtualBox guests lose shared folder and networking on host suspend resume
VirtualBox (in my case, vagrant-managed) local-only network connections (and, e.g. NFS shares piped through them) fail when the host syspends and resumes. NetworkManager (or possibly another network managers) are interfering. If you use NetworkManager, get it out of the way by adding:
to your /etc/NetworkManager/NetworkManager.conf. (Additional interfaces can be listed after a semi-colon). If you need to read this later and get back to work NOW, try this:
VBoxManage hostonlyif ipconfig vboxnet0 --ip 192.your.subnet.1
When an active virtual machine is running, and the host is suspended, upon resume:
- NFS shared folders are unavailable within the guest
- host-only network is unreachable in the guest
- The host network adapter (vboxnetX) is ACTIVE yet has no IP address
In my case, NetworkManager was attempting to manage the interfaces, for which it does not have configuration. Network manager clears the IP address assigned to the network adapter (typically vboxnet[0...]), disabling communication to the host from the guest. As your computer goes to sleep, you may see a similar entry in your logs:
NetworkManager: <info> (vboxnet0): device state change: activated -> unmanaged (reason 'sleeping').
If NetworkManager is your current network management software, you can disable it's management of certain interfaces by adding the following to your to /etc/NetworkManager/NetworkManager.conf:
Additional interfaces (e.g. vboxnet1) can be specified on the same line by adding a semicolon, and repeating the selection (e.g. add ';interface-name:vboxnet1').
If you cannot modify the system for some reason (which I'd find odd), or just want to make the adapter work immediately, you can use either of these methods to bring the machine back, without losing anything:
Simply suspend the machine and bring it back up:
vagrant suspend && vagrant resume
Or, directly reactivate the network adapter for the internal networking, for example, my guest has the fixed IP 192.168.36.10, so I give the adapter the x.x.x.1 address with:
VBoxManage hostonlyif ipconfig vboxnet0 --ip 192.168.36.1
I found the solution thanks to this bug report. There's also mention there of using an asterisk for NetworkManager's configuration for the numeric portion of the adapter name if you have multiple, which I certainly do! Alas, this did not work for me (version 0.9.10.0).
There is another possibility for making this work, however my attempts at this also failed. Using udev, you can flag an interface (or set of interfaces - asterisk support definitly works here!) such that NetworkManager automatically ignores it. The NetworkManager documentation mentions an NM_UNMANAGED flag. Frankly, I'm not sure how to set it - I tried creating a rules file in /etc/udev/rules.d/z21_persistent-local.rules, and do see that it takes effect with udevadm, however, this did not make NetworkManager ignore the interface. It seems YMMV!
# udevadm info --path=/devices/virtual/net/vboxnet0
I did also try using true for this value with the same result (1 or true are supposed to work).
I believe it is possible to use a single interface for all your local-only hosts. This should also allow the guests to communicate with one another privately (which you may not want). If this method interests you, you may want to start here.