User login

VirtualBox guests lose shared folder and networking on host suspend resume

TLDR

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:
[keyfile]
unmanaged-devices=interface-name:vboxnet0

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

Symptom

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

Cause:

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[440]: <info>  (vboxnet0):  device state change: activated -> unmanaged (reason 'sleeping').

Resolution

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:
[keyfile]
unmanaged-devices=interface-name:vboxnet0

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!

udev rule:
SUBSYSTEM=="net",DEVPATH=="/devices/virtual/net/vboxnet*",ACTION=="add",ENV{NM_UNMANAGED}="1"

Testing udev:
# udevadm info --path=/devices/virtual/net/vboxnet0
P: /devices/virtual/net/vboxnet0
E: DEVPATH=/devices/virtual/net/vboxnet0
E: ID_MM_CANDIDATE=1
E: ID_NET_DRIVER=vboxnet
E: ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
E: ID_NET_NAME_MAC=enx0a0027000000
E: IFINDEX=4
E: INTERFACE=vboxnet0
E: NM_UNMANAGED=1
E: SUBSYSTEM=net
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/vboxnet0
E: TAGS=:systemd:
E: USEC_INITIALIZED=196437389

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.

Searched words: 
vbox VirtualBox vagrant nfs networking hang NetworkManager

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.