Error while installing Virtualbox guest additions in Ubuntu 20.04.2: Look at /var/log/vboxadd-setup.log to find out what went wrong

This seems to be a problem caused by a VirtualBox bug. This is what I encountered:

I use Ubuntu 16.04 with kernel 4.4.0-210, after upgrade VirtualBox to 6.1.22, I meet with the problem described above. I solved it with @Jamie Brown's sulution. Thank you!

Then I found VirtualBox changelog at https://www.virtualbox.org/wiki/Changelog-6.1 say:

VirtualBox 6.1.24 (released July 20 2021)

Linux Guest Additions: Introduce support for Ubuntu specific kernels (bug #20325)

And the bug ticket page say: When installing Guest Additions from 6.1.20 in kernel 4.4.0.210-generic (Ubuntu 16.04) module vboxsf fails compiling with exactly same error as #18697.

So this is a bug introduced in 6.1.20 and solved in 6.1.24, and only cause error with some specific kernel.


I had the same issue - suddenly today my Vagrant box stopped mounting my shared folders, and kept failing to update the Virtual Guest Additions every time it started:

==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.18
VBoxService inside the vm claims: 6.1.18
Going on, assuming VBoxService is correct...
[default] GuestAdditions seems to be installed (6.1.18) correctly, but not running.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.18
VBoxService inside the vm claims: 6.1.18
Going on, assuming VBoxService is correct...
Job for vboxadd-service.service failed because the control process exited with error code. See "systemctl status vboxadd-service.service" and "journalctl -xe" for details.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.18
VBoxService inside the vm claims: 6.1.18
Going on, assuming VBoxService is correct...
update-initramfs: Generating /boot/initrd.img-4.4.0-209-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
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: Building the modules for kernel 4.4.0-209-generic.

VirtualBox Guest Additions: Look at /var/log/vboxadd-setup.log to find out what 
went wrong
VirtualBox Guest Additions: Running kernel modules will not be replaced until 
the system is restarted
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.18
VBoxService inside the vm claims: 6.1.18
Going on, assuming VBoxService is correct...
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.0.18
VBoxService inside the vm claims: 6.1.18
Going on, assuming VBoxService is correct...
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: Configuring and enabling network interfaces...
==> default: Mounting shared folders...

The log was no help, it just said this:

vagrant@ubuntu-xenial:~$ cat /var/log/vboxadd-setup.log
Could not find the X.Org or XFree86 Window System, skipping.

After messing around for ages and reading several StackOverflow answers from a few years ago (none of which helped) I upgraded my kernel:

vagrant@ubuntu-xenial:~$ wget https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh
sudo install ubuntu-mainline-kernel.sh /usr/local/bin/
ubuntu-mainline-kernel.sh -c
sudo ubuntu-mainline-kernel.sh -i v5.11.15

And then restarted with vagrant halt and vagrant up, and the VB Guest Additions got themselves all sorted out.

So if you've got an old box, it looks like the latest VirtualBox Guest Additions do not play nice and you need to update your kernel.