dotless-de / vagrant-vbguest

A Vagrant plugin to keep your VirtualBox Guest Additions up to date
MIT License
2.88k stars 206 forks source link

GuestAdditions sometimes detected as running, sometimes not 🤷‍♂️ #421

Closed kohanyirobert closed 9 months ago

kohanyirobert commented 2 years ago

I have a multi-machine setup (not sure if this is relevant or not) and when I run vagrant up the plugin always rebuilds kernel modules, etc., not sure why but it takes a tremendous amount of time with 3 VMs. Everything else is a-okay with the VMs, just the fact that at every boot GuestAdditions are rebuilt. I tried to reload them, to no change. The following is what I have found out.

$ vagrant --version
Vagrant 2.2.19
$ vagrant plugin list
vagrant-vbguest (0.30.0, global)
  - Version Constraint: > 0

I just run these two commands, after each other, the first execution was successful, the second not.

Note: a is my machine's name.

$ vagrant vbguest a --status
[a] GuestAdditions 6.1.32 running --- OK.
$ vagrant vbguest a --status
[a] GuestAdditions seems to be installed (6.1.32) correctly, but not running.

I've tracked down that linux.rb decides whether things are running or not by checking for modules in /proc/modules. So I ran this

$ vagrant ssh a -- "sudo cat /proc/modules | grep -iP '^(vboxguest|vboxsf)\b'"
vboxsf 77824 1 - Live 0xffffffffc067b000 (OE)
vboxguest 339968 2 vboxsf, Live 0xffffffffc073b000 (OE)

Ran it a few times but the modules are always there ... so I've hacked this two lines into linux.rb before the regex test

env.ui.warn "KMODS START"
env.ui.warn kmods
env.ui.warn "KMODS END"

... and sure enough, when I run vagrant vbguest a --status sometimes the kmods doesn't contain the lines for required modules.

Any idea why this can be happening? :O

I have my whole setup in this repo (link points to the particular commit where I noticed the problem). (**If anyone plans to run it, generate an SSH key in the repo's root called id_rsa - ssh-keygen -f id_rsa.)

One though: I'm using linked_clones, not sure if this matters - my first thought was maybe the plugin connects to the wrong VM or something, but this doesn't seem to be the case.

Just for good measure I'm thrown in a log file from running vagrant vbguest a --do install --debug 2>&1 | tee vbguest.log. And here's another running --status instead. Note: this last log contain (as far as I remember my hack introduced into linux.rb, the KMODS prints and hereby I solemnly swear I didn't hack anything else).

I see a few errors like this in the logs:

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: cat /proc/modules (sudo=true)
DEBUG ssh: stderr: mesg: ttyname failed: Inappropriate ioctl for device

Not sure if this is relevant, because cat /proc/modules always "successful", however sometimes the required modules are missing :S

fnordfish commented 2 years ago

IIRC, the module for the shared filesystem (vboxsf) is recently loaded on demand and might not be in the early stages where vbguest runs.

Try to limit the check for which modules should be loaded like this:

Vagrant.configure("2") do |config|
  config.vbguest.installer_options = { running_kernel_modules: ["vboxguest"] }
end

See https://github.com/dotless-de/vagrant-vbguest#installer-specific-options-installer_options for possible quirks in multi VM setups

kohanyirobert commented 2 years ago

IIRC, the module for the shared filesystem (vboxsf) is recently loaded on demand and might not be in the early stages where vbguest runs.

If you check the log I've attached to my first post and search for KMODS you can see that the plugin can't see any of the VirtualBox related modules, so I don't think this to be the problem. Also, even if vbguest reports that guest additions are not running shared folder functionality works always - I'm not an expert at kernel module loading, but if once a module has been loaded I wouldn't think it gets paged out or something.

Try to limit the check for which modules should be loaded

Already doing that as a workaround, forgot to mention that.