Ubuntu – Virtualbox broken after a dist-upgrade — cannot install virtuabox-dkms nor run modprobe vboxdrv

dkmskernelmodprobeupgradevirtualbox

I am running Ubuntu 20.04 and recently did a dist-upgrade.

uname -r: 5.8.0-34-generic

I purged Virtualbox and associate files by:

sudo apt-get purge "^virtualbox-.*"

After trying to reinstall any software I get the following now:

>>$ sudo apt install --reinstall linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
3 not fully installed or removed.
Need to get 0 B/1,236 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 328260 files and directories currently installed.)
Preparing to unpack .../linux-headers-5.8.0-34-generic_5.8.0-34.37~20.04.2_amd64.deb ...
Unpacking linux-headers-5.8.0-34-generic (5.8.0-34.37~20.04.2) over (5.8.0-34.37~20.04.2) ...
Setting up linux-headers-5.8.0-34-generic (5.8.0-34.37~20.04.2) ...
/etc/kernel/header_postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.8.0-34-generic

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
make -j8 KERNELRELEASE=5.8.0-34-generic -C /lib/modules/5.8.0-34-generic/build M=/var/lib/dkms/virtualbox/6.1.10/build...(bad exit status: 2)
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/virtualbox-dkms.0.crash'
Error! Bad return status for module build on kernel: 5.8.0-34-generic (x86_64)
Consult /var/lib/dkms/virtualbox/6.1.10/build/make.log for more information.
   ...done.
Setting up virtualbox-dkms (6.1.10-dfsg-1~ubuntu1.20.04.1) ...
Removing old virtualbox-6.1.10 DKMS files...

------------------------------
Deleting module version: 6.1.10
completely from the DKMS tree.
------------------------------
Done.
Loading new virtualbox-6.1.10 DKMS files...
Building for 5.8.0-34-generic
Building initial module for 5.8.0-34-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/virtualbox-dkms.0.crash'
Error! Bad return status for module build on kernel: 5.8.0-34-generic (x86_64)
Consult /var/lib/dkms/virtualbox/6.1.10/build/make.log for more information.
dpkg: error processing package virtualbox-dkms (--configure):
 installed virtualbox-dkms package post-installation script subprocess returned error exit status 10
dpkg: dependency problems prevent configuration of virtualbox:
 virtualbox depends on virtualbox-dkms (>= 6.1.10-dfsg-1~ubuntu1.20.04.1) | virtualbox-source (>= 6.1.10-dfsg-1~ubuntu1.20.04.1) | virtualbox-modules; however:
  Package virtualbox-dkms is not configured yet.
  Package virtualbox-source is not installed.
  Package virtualbox-modules is not installed.
  Package virtualbox-dkms which provides virtualbox-modules is not configured yet.

dpkg: error processing package virtualbox (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of virtualbox-qt:
 virtualbox-qt depends on virtualbox (= 6.1.10-dfsg-1~ubuntu1.20.04.1); however:
  Package virtualbox is not configured yet.

dpkg: error processing package virtualbox-qt (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          No apport report written because the error message indicates its a followup err
or from a previous failure.
                           Errors were encountered while processing:
 virtualbox-dkms
 virtualbox
 virtualbox-qt
E: Sub-process /usr/bin/dpkg returned an error code (1)

Running

sudo apt-get install -f

Does not fix the dependency problem. I still get the same output:

>>$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up virtualbox-dkms (6.1.10-dfsg-1~ubuntu1.20.04.1) ...
Removing old virtualbox-6.1.10 DKMS files...

------------------------------
Deleting module version: 6.1.10
completely from the DKMS tree.
------------------------------
Done.
Loading new virtualbox-6.1.10 DKMS files...
Building for 5.8.0-34-generic
Building initial module for 5.8.0-34-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/virtualbox-dkms.0.crash'
Error! Bad return status for module build on kernel: 5.8.0-34-generic (x86_64)
Consult /var/lib/dkms/virtualbox/6.1.10/build/make.log for more information.
dpkg: error processing package virtualbox-dkms (--configure):
 installed virtualbox-dkms package post-installation script subprocess returned error exit status 10
dpkg: dependency problems prevent configuration of virtualbox:
 virtualbox depends on virtualbox-dkms (>= 6.1.10-dfsg-1~ubuntu1.20.04.1) | virtualbox-source (>= 6.1.10-dfsg-1~ubuntu1.20.04.1) | virtualbox-modules; however:
  Package virtualbox-dkms is not configured yet.
  Package virtualbox-source is not installed.
  Package virtualbox-modules is not installed.
  Package virtualbox-dkms which provides virtualbox-modules is not configured yet.

dpkg: error processing package virtualbox (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of virtualbox-qt:
 virtualbox-qt depends on virtualbox (= 6.1.10-dfsg-1~ubuntu1.20.04.1); however:
  Package virtualbox is not configured yet.

dpkg: error processing package virtualbox-qt (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          No apport report written because the error message indicates its a followup error from a previous failure.
                           Errors were encountered while processing:
 virtualbox-dkms
 virtualbox
 virtualbox-qt
E: Sub-process /usr/bin/dpkg returned an error code (1)

Reconfiguring as below yields the same message:

sudo dpkg --configure -a

The crash report located at /var/crash/virtualbox-dkms.0.crash indicates the following:

ProblemType: Package
DKMSBuildLog:
 DKMS make.log for virtualbox-6.1.10 for kernel 5.8.0-34-generic (x86_64)
 Thursday, January 07, 2021 AM09:37:43 HKT
 make: Entering directory '/usr/src/linux-headers-5.8.0-34-generic'
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrv.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrvGip.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrvSem.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrvTracer.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPLibAll.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/alloc-r0drv.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/initterm-r0drv.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/memobj-r0drv.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/mpnotification-r0drv.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/powernotification-r0drv.o
   CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/assert-r0drv-linux.o
 In file included from ./include/asm-generic/percpu.h:7,
                  from ./arch/x86/include/asm/percpu.h:556,
                  from ./arch/x86/include/asm/preempt.h:6,
                  from ./include/linux/preempt.h:78,
                  from ./include/linux/spinlock.h:51,
                  from /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/../SUPDrvInternal.h:79,
                  from /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.c:32:
 /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.c: In function ‘supdrvOSChangeCR4’:
 /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.c:760:38: error: ‘cpu_tlbstate’ undeclared (first use in this function); did you mean ‘cpuhp_state’?
   760 |     RTCCUINTREG uOld = this_cpu_read(cpu_tlbstate.cr4);
       |                                      ^~~~~~~~~~~~
 ./include/linux/percpu-defs.h:318:9: note: in definition of macro ‘__pcpu_size_call_return’
   318 |  typeof(variable) pscr_ret__;     \
       |         ^~~~~~~~
 /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.c:760:24: note: in expansion of macro ‘this_cpu_read’
   760 |     RTCCUINTREG uOld = this_cpu_read(cpu_tlbstate.cr4);
       |                        ^~~~~~~~~~~~~
 /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.c:760:38: note: each undeclared identifier is reported only once for each function it appears in
   760 |     RTCCUINTREG uOld = this_cpu_read(cpu_tlbstate.cr4);
       |                                      ^~~~~~~~~~~~
 ./include/linux/percpu-defs.h:318:9: note: in definition of macro ‘__pcpu_size_call_return’
   318 |  typeof(variable) pscr_ret__;     \
       |         ^~~~~~~~
 /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.c:760:24: note: in expansion of macro ‘this_cpu_read’
   760 |     RTCCUINTREG uOld = this_cpu_read(cpu_tlbstate.cr4);
       |                        ^~~~~~~~~~~~~
 make[2]: *** [scripts/Makefile.build:288: /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.o] Error 1
 make[2]: *** Waiting for unfinished jobs....
 make[1]: *** [scripts/Makefile.build:519: /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv] Error 2
 make: *** [Makefile:1780: /var/lib/dkms/virtualbox/6.1.10/build] Error 2
 make: Leaving directory '/usr/src/linux-headers-5.8.0-34-generic'
DKMSKernelVersion: 5.8.0-34-generic
Date: Thu Jan  7 09:37:46 2021
DuplicateSignature: dkms:virtualbox-dkms:6.1.10-dfsg-1~ubuntu1.20.04.1:/var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.c:760:38: error: ‘cpu_tlbstate’ undeclared (first use in this function); did you mean ‘cpuhp_state’?
Package: virtualbox-dkms 6.1.10-dfsg-1~ubuntu1.20.04.1
PackageVersion: 6.1.10-dfsg-1~ubuntu1.20.04.1
SourcePackage: virtualbox
Title: virtualbox-dkms 6.1.10-dfsg-1~ubuntu1.20.04.1: virtualbox kernel module failed to build

Any help is appreciated.


After input from @Terrace and others, I tried installing from source. But I still get an error in installing virtualbox-dkms. After that, I uninstalled virtual-dkms directly:

sudo apt-get remove virtualbox-dkms

And then re-attempted the install

sudo dpkg -i virtualbox-6.1_6.1.16-140961~Ubuntu~eoan_amd64.deb
```

Wich succeeded. Thank you!

Best Answer

Update

Note:
- This guide will become irrelevant in the near future when proposed migrates to release.

  • 6.1.16-dfsg-6~ubuntu1.20.04.1 is now in the Store 'ubuntu-focal-updates-multiverse' and 5.8 kernel had a few updates with current 5.8.0-40-generic
    Should not be an issue if one keeps up with regular updates.

  • Suggested options 1 and 4 to have future automatic updates for VirtualBox.
  • Option 2, 3a, 3b manual installation does not include automatic future updates for VirtualBox.

Bug

Installation of VirtualBox 6.1.16 on Ubuntu 20.04

Option 1 (Easy)

Pre-released updates (focal-proposed)

    • Open Software & Updates
    • Developer Options
    • select ✅ Pre-released updates (focal-proposed)
    • select Close
    • on Popup The information about available software is out-of-date
      select Reload
    • Open Software Updater
    • deselect all/any other updates except VirtualBox (which will include multiple packages in its subcategory)
    • select Install Now

Previous post

Bug virtualbox-dkms 6.1.10-dfsg-1~ubuntu1.20.04.1 fails to build with kernel 5.8
I followed @Terrance advice and installed 6.1.16 from the source.
My previous VMs are all working.

Edit: Per @BeastOfCaerbannog request/suggestion.


Installation of VirtualBox 6.1.16 on Ubuntu 20.04

Option 2 (Easy)

*if GDebi is not installed > go to Software Store and install it
*if Error: Conflicts with the installed package 'virtualbox-qt' > go to Software Store and Remove Virtualbox 6.1.10


Option 3 a. (Easy)

Option 3 b. (Advanced)

  • In Terminal
cd Downloads 
sudo apt install ./virtualbox-6.1_6.1.16-140961~Ubuntu~eoan_amd64.deb

or

sudo apt install ./v*  

Option 4 (Advanced)

Install Virtualbox by using the Virtualbox repos

 
thanks @Terrance

Related Question