github email rss
VirtualBox Guest Additions on CentOS Linux
Apr 9, 2017
3 minutes read

Many users of the official CentOS Linux images for Vagrant use VirtualBox, and would prefer to have the VirtualBox Guest Additions preinstalled. My early packaging attemps were stopped by compilation errors (apparently GCC bug #49718, fixed in the GCC 4.9 development branch – unfortunately, CentOS Linux 7.2.1511 uses GCC 4.8.5 as its system compiler):

kBuild: Compiling RuntimeGuestR0 - /home/vagrant/VirtualBox-5.0.26/src/VBox/Runtime/common/alloc/alloc.cpp
In file included from /home/vagrant/VirtualBox-5.0.26/include/iprt/types.h:116:0,
				 from /home/vagrant/VirtualBox-5.0.26/include/iprt/mem.h:31,
				 from /home/vagrant/VirtualBox-5.0.26/src/VBox/Runtime/common/alloc/alloc.cpp:34:
/lib/modules/3.10.0-327.28.3.el7.x86_64/build/include/linux/compiler.h:184:29: error: can’t set ‘no_instrument_function’ attribute after definition
 static __always_inline void __read_once_size(const volatile void *p, void *res, int size)
/lib/modules/3.10.0-327.28.3.el7.x86_64/build/include/linux/compiler.h:198:29: error: can’t set ‘no_instrument_function’ attribute after definition
 static __always_inline void __write_once_size(volatile void *p, void *res, int size)
kmk: *** [/home/vagrant/VirtualBox-5.0.26/out/linux.amd64/release/obj/RuntimeGuestR0/common/alloc/alloc.o] Error 1

In addition, I have some concerns about including them by default:

  • as out-of-tree modules, the VirtualBox Guest Additions taint the kernel, which means the Linux developers won’t accept any bug reports about kernel crashes
  • they need to be recompiled every time a kernel update is installed, significantly slowing down the update process
  • the development tools required for recompilation increase the size of our images by around 180MB – almost 50%

Nevertheless, if you want to automatically install the Guest Additions inside the new Vagrant boxes that you create, you can either use the vagrant-vbguest plugin for Vagrant, or my Cloud Instance Starter Kit for Ansible.


This is probably the easiest option, since it doesn’t have any dependencies besides Vagrant itself. You only need to install the plugin once:

vagrant plugin install vagrant-vbguest

That’s all! All Vagrant boxes will automatically install the VirtualBox Guest Additions, and update them as necessary. It works on any host OS and with any Linux distribution as a guest, not just with CentOS Linux.

The only downside is that it compiles the Guest Additions for the current guest kernel, which means you’ll have to wait twice for the compilation, if there’s a newer kernel available since the Vagrant image was created. Additionally, in the case of CentOS Linux, vagrant-vbguest fails across CentOS Linux point releases, because vagrant-vbguest doesn’t know how to retrieve the older packages it needs from the CentOS Vault, where they are moved in the release process.

Cloud Instance Starter Kit

If you already have Ansible installed on the host, you can use my Cloud Instance Starter Kit to automatically install the VirtualBox Guest Additions. It will first update all packages in the guest to their latest version, reboot the guest if necessary, and then install the Guest Additions and reboot one more time. You can even repackage the box and import it into Vagrant:

vagrant up # this will take several minutes...
vagrant halt
vagrant package
vagrant box add --name c7

This approach has the advantage of not breaking across CentOS Linux point releases, not having to wait twice for the compilation, and leaving you with a fully updated guest system, with the Guest Additions installed. Its only disadvantage is that it requires Ansible, which doesn’t run on Windows.

Back to posts