Fixing vagrant-vbguest for the centos/7 base box

February 25, 2021 

We're using the centos/7 base box in Vagrant a lot and often hit this problem when bringing up new VMs with Vagrant:

umount: /mnt: not mounted

This error comes from vagrant-vbguest plugin which tried to install the Virtualbox Guest Additions but failed. The error message is misleading, because the real issue is related to upstream (CentOS) yum repositories. As explained in this Vagrant bug report:

"Basically the CentOS that you're installing is containing an old kernel version which has been removed from CentOS repositories. Vagrant is trying to install Guest Additions, which has as a dependency the kernel-devel package. kernel-devel package must be the same version as the kernel package that you have it installed in your CentOS box, version which is removed from the CentOS repos."

There seem to be many hacky workarounds to this like:

  • Downgrading vagrant-vbguest: if this works, it probably only works because its defaults changed to "worse" at some point.
  • Rebuilding the centos/7 base box yourself. This certainly works, but seems like an overkill.

Fortunately there is also a clean CentOS-specific solution described in vagrant-vbguest's documentation:

:allow_kernel_upgrade (default: false): If true, instead of trying to find matching the matching kernel-devel package to the installed kernel version, the kernel will be updated and the (now matching) up-to-date kernel-devel will be installed. NOTE: This will trigger a reboot of the box.
vagrant-vbguest documentation
Tweet

This can be defined on a global or on a per-box level:

config.vm.define "centos7" do |box|
  box.vm.box = "centos/7"
  box.vm.box_version = "2004.01"
  box.vbguest.installer_options = { allow_kernel_upgrade: true }
  --- snip ---

This should do it.

Samuli Seppänen
Samuli Seppänen
Author archive
menucross-circle