dotless-de / vagrant-vbguest

A Vagrant plugin to keep your VirtualBox Guest Additions up to date

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

almalinux: "/sbin/mount.vboxsf: mounting failed with the error: No such device" for vagrant-vbguest > 0.21

marc-guenther opened this issue · comments

Installation fails on almalinux/8 with vagrant-vbguest versions 0.22 and later with the following error:

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000,_netdev vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

Downgrading to version 0.21 fixes the problem.

To reproduce:

vagrant plugin install vagrant-vbguest
vagrant init almalinux/8
vagrant up

Complete log:

admin@macmini2020e vagrant-test % vagrant --version                       
Vagrant 2.2.19
admin@macmini2020e vagrant-test % vagrant plugin install vagrant-vbguest                      
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching micromachine-3.0.0.gem
Fetching vagrant-vbguest-0.30.0.gem
Installed the plugin 'vagrant-vbguest (0.30.0)'!
admin@macmini2020e vagrant-test % vagrant init almalinux/8
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
admin@macmini2020e vagrant-test % vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'almalinux/8'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'almalinux/8' version '8.6.20220513' is up to date...
==> default: Setting the name of the VM: vagrant-test_default_1653676739872_49106
==> default: Fixed port collision for 22 => 2222. Now on port 2208.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2208 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2208
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
[default] GuestAdditions seems to be installed (6.1.28) correctly, but not running.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel 
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel 
4.18.0-372.9.1.el8.x86_64. Please install them and execute
  /sbin/rcvboxadd setup
VirtualBox Guest Additions: Running kernel modules will not be replaced until 
the system is restarted
Restarting VM to apply changes...
==> default: Attempting graceful shutdown of VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default: 
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Mounting shared folders...
    default: /vagrant => /Users/admin/vagrant-test
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000,_netdev vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

admin@macmini2020e vagrant-test % client_loop: send disconnect: Broken pipe

This is on:

  • MacOS 10.15.7 (Catalina)
  • VirtualBox 6.1.16r140961
  • Vagrant 2.2.19

This line appears to be your problem (I'm also have a similar issue):

VirtualBox Guest Additions: Kernel headers not found for target kernel

A "chicken and egg" issue - the running kernel in the base box doesn't have the proper kernel header source installed for the Guest Additions to build properly, but the current kernel-headers packages match the current kernel, which isn't running in the box. If the kernel headers don't match then the Guest Additions build will fail. Hence vboxsf is not being inserted into the running kernel. I believe that's the problem you're facing.

Trying to specify the exact kernel-header package doesn't seem to work either as it seems older kernel-header packages are removed from the base/updates repos (at least for Rocky Linux - it may work for Alma)

One workaround to try is to vagrant ssh to the box, upgrade the running kernel, and install the proper kernel-devel and kernel-headers packages, along with the proper build packages (bzip2 elfutils-libelf-devel gcc kernel-devel kernel-headers make perl tar). You could also see if the kernel-headers for your running kernel are available in a repo somewhere.

You can also try to install those required pacakges with the installer_hooks config option:

vm.vbguest.installer_hooks[:before_install] = ["yum -y install bzip2 elfutils-libelf-devel gcc kernel-devel kernel-headers make perl tar", "sleep 2"]

That command won't work directly because I'm guessing kernel-headers will install the most recent kernel headers and not the one for your running kernel. That's the boat that I'm in.

Depending on your distro you may or may not be able to install the proper version of the kernel headers. this is the case I'm trying to find a solution to.

The following would be good for the vbguest plugin to perform as a kernel-headers mismatch seems to be a fairly regular case (at least with RH linux variants - centos, rocky, etc):

  • Check if allow_kernel_upgrade is true
  • IF TRUE
    • Upgrade kernel and install proper build dependency packages
    • Reboot
    • Upon restart try guest additions ISO mount and installation
  • ELSE
    • Warning the user that the installation may fail if allow_kernel_upgrade is false
    • Proceed with guest additions ISO mount and installation

Another check could be run uname -r (or equivalent Ruby code) and verify that the kernel headers installed match the running kernel. If there is a mismatch and allow_kernel_upgrade is true then perform the same steps as my TRUE pseudo-code block above.

I know no Ruby code, nor syntax. I will try to build a pull request to add this functionality, but would like to hear from the vagrant-vbguest maintainers to hear their thoughts on this use case. This case seems fairly common, but they probably have more wisdom than I 😁

Follow-up: for my situation, adding the following to my Vagrantfile worked to get guest additions running (if you don't mind upgrading the kernel in your vagrant box):

    # Get the kernel inside the box upgraded so VBox Guest Additions work
    app1.vbguest.installer_options = { allow_kernel_upgrade: true, auto_reboot: true }
    app1.vbguest.installer_hooks[:before_install] = ["dnf -y install bzip2 elfutils-libelf-devel gcc kernel kernel-devel kernel-headers make perl tar", "sleep 2"]

dnf works on newer fedora/redhat/rocky variants. If you don't have dnf just change the command to yum

Change app1 to the name of your vm or if you have a standard Vagrant.configure("2") do |config| loop I think you would change app1 to config.vm (I'm a newb vagrant user so it may take some fiddling to get the proper option).

I still initially received the message about Kernel headers not found however after my vagrant box rebooted vboxsf was installed into the running kernel and sync_folders worked.

Good luck!

Thanks for the detailed analysis. What I don't understand, why does it seem to work with 0.21? Or at least, there is no error message with 0.21.

You mentioned Rocky. Is there a notable difference between Alma and Rocky?

Just was bitten by this again. We moved our services to a new host, and of course I forgot to downgrade the plugin. Current version is 0.31, and still same problem.

Apparently in the mean time:

  • support for Rocky has been added: #424
  • but not support for Alma: #430

Both distros claim to be binary-compatible, so I think they can be treated the same?

Anyway, I moved my box to Oraclelinux, and all is fine now.