VirtualBox not starting after kernel upgrade

Yesterday I received a kernel upgrade and after reboot, VirtualBox stopped working.

Here is my system info (after kernel upgrade):

matteo@workstation:~$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
matteo@workstation:~$ uname -a
Linux workstation 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

I installed VirtualBox long ago with

sudo apt install linux-headers-$(uname -r)
sudo apt install virtualbox-dkms virtualbox virtualbox-qt

used on daily basis and never had problems with kernel updates. The error I receive now is

matteo@workstation:~$ sudo modprobe vboxdrv
modprobe: ERROR: could not insert 'vboxdrv': Exec format error
matteo@workstation:~$ dmesg | tail -n 1
[ 1413.167311] vboxdrv: version magic '4.4.0-116-generic SMP mod_unload modversions ' should be '4.4.0-116-generic SMP mod_unload modversions retpoline '

I found a forum post with this error message here from three days ago, unfortunately without resolution. Therfore I tried to remove the VirtualBox packeges from the Ubuntu repo, and install the latest 5.2 using this procedure. However, even after rebooting the machine, the error remains.

What can I do in this case?


Solution 1:

I was facing the same problem. After kernel upgrade my gcc version was showing as 5.4.1. Downgrading this version to 5.4.0 helped me to have retpoline for vboxdrv kernel module.

Following steps from this link helped me solve my issue:

sudo apt-get install ppa-purge
sudo ppa-purge ppa:ubuntu-toolchain-r/test
#Select gcc version 5 using update-alternatives manually
sudo update-alternatives --config gcc

After these steps gcc --version should be (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609

Then purge all the new linux headers (4.4.0-116)

sudo apt-get purge linux-headers-4.4.0-116 linux-headers-4.4.0-116-generic linux-image-4.4.0-116-generic linux-image-extra-4.4.0-116-generic linux-signed-image-4.4.0-116-generic

Again install them

sudo apt-get install linux-generic linux-signed-generic

Then re-install virtualbox, I installed latest virtualbox-5.2 this time, but default 5.0 version of virtualbox should also work fine.

sudo apt-get purge virtualbox-dkms virtualbox virtualbox-qt
sudo apt-get install virtualbox-5.2

And, we have retpoline support in latest module

anirudh@AHDRMD34579:~$ modinfo vboxdrv 
filename:       /lib/modules/4.4.0-116-generic/misc/vboxdrv.ko
version:        5.2.6 r120293 (0x00290000)
license:        GPL
description:    Oracle VM VirtualBox Support Driver
author:         Oracle Corporation
srcversion:     4880B21EFF1B605D6402982
depends:        
vermagic:       4.4.0-116-generic SMP mod_unload modversions retpoline 
parm:           force_async_tsc:force the asynchronous TSC mode (int)

Solution 2:

The related problem listed in @ricab 's comment has been traced down to a problem with the new kernel requiring a certain version level of gcc to successfully compile kernel modules.

On my system the gcc update was pushed out AFTER the kernel update, causing the recompiles to fail.

Once the root cause was discovered, I was able to fix the system by uninistalling and reinstalling the new kernel. That fixed my graphics drivers, but I had to issue sudo /sbin/vboxconfig to fix virtualbox after booting into the new kernel.

My system is 14.04 so I cannot advise you as to the proper version of gcc for your 16.04 system, but this is discussed at https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/1750937