Friday 5 April 2019

How to install VirtualBox on Ubuntu 18.04

Go to VirtualBox Linux Downloads page and download the latest .deb package for Ubuntu 18.04.

Install it:

$ sudo dpkg -i virtualbox-6.0_6.0.4-128413_Ubuntu_bionic_amd64.deb
[sudo] password for user:
Selecting previously unselected package virtualbox-6.0.
(Reading database ... 178490 files and directories currently installed.)
Preparing to unpack virtualbox-6.0_6.0.4-128413_Ubuntu_bionic_amd64.deb ...
Unpacking virtualbox-6.0 (6.0.4-128413~Ubuntu~bionic) ...
dpkg: dependency problems prevent configuration of virtualbox-6.0:
 virtualbox-6.0 depends on libqt5core5a (>= 5.9.0~beta); however:
  Package libqt5core5a is not installed.
 virtualbox-6.0 depends on libqt5gui5 (>= 5.4.0); however:
  Package libqt5gui5 is not installed.
 virtualbox-6.0 depends on libqt5opengl5 (>= 5.0.2); however:
  Package libqt5opengl5 is not installed.
 virtualbox-6.0 depends on libqt5printsupport5 (>= 5.0.2); however:
  Package libqt5printsupport5 is not installed.
 virtualbox-6.0 depends on libqt5widgets5 (>= 5.7.0); however:
  Package libqt5widgets5 is not installed.
 virtualbox-6.0 depends on libqt5x11extras5 (>= 5.6.0); however:
  Package libqt5x11extras5 is not installed.
 virtualbox-6.0 depends on libsdl1.2debian (>= 1.2.11); however:
  Package libsdl1.2debian is not installed.

dpkg: error processing package virtualbox-6.0 (--install):
 dependency problems - leaving unconfigured
Processing triggers for systemd (237-3ubuntu10.15) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for shared-mime-info (1.9-2) ...
Errors were encountered while processing:

I tried to fix the error with:

$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree     
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libdouble-conversion1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5opengl5 libqt5printsupport5 libqt5svg5 libqt5widgets5 libqt5x11extras5
  libsdl1.2debian libxcb-xinerama0 qt5-gtk-platformtheme qttranslations5-l10n
Suggested packages:
  qt5-image-formats-plugins qtwayland5
The following NEW packages will be installed
  libdouble-conversion1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5opengl5 libqt5printsupport5 libqt5svg5 libqt5widgets5 libqt5x11extras5
  libsdl1.2debian libxcb-xinerama0 qt5-gtk-platformtheme qttranslations5-l10n
0 to upgrade, 14 to newly install, 0 to remove and 11 not to upgrade.
1 not fully installed or removed.
Need to get 9,896 kB of archives.
After this operation, 42.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 bionic/main amd64 libdouble-conversion1 amd64 2.0.1-4ubuntu1 [33.0 kB]
Get:2 bionic-updates/main amd64 libqt5core5a amd64 5.9.5+dfsg-0ubuntu2 [2,037 kB]
Get:3 bionic-updates/main amd64 libqt5dbus5 amd64 5.9.5+dfsg-0ubuntu2 [195 kB]                                                 
Get:4 bionic-updates/main amd64 libqt5network5 amd64 5.9.5+dfsg-0ubuntu2 [633 kB]                                               
Get:5 bionic-updates/main amd64 libxcb-xinerama0 amd64 1.13-2~ubuntu18.04 [5,264 B]                                             
Get:6 bionic-updates/main amd64 libqt5gui5 amd64 5.9.5+dfsg-0ubuntu2 [2,566 kB]                                                 
Get:7 bionic-updates/main amd64 libqt5widgets5 amd64 5.9.5+dfsg-0ubuntu2 [2,205 kB]                                             
Get:8 bionic-updates/main amd64 libqt5opengl5 amd64 5.9.5+dfsg-0ubuntu2 [132 kB]                                               
Get:9 bionic-updates/main amd64 libqt5printsupport5 amd64 5.9.5+dfsg-0ubuntu2 [178 kB]                                         
Get:10 bionic/universe amd64 libqt5x11extras5 amd64 5.9.5-0ubuntu1 [8,596 B]                                                   
Get:11 bionic/main amd64 libsdl1.2debian amd64 1.2.15+dfsg2-0.1 [174 kB]                                                       
Get:12 bionic/main amd64 libqt5svg5 amd64 5.9.5-0ubuntu1 [128 kB]                                                               
Get:13 bionic-updates/main amd64 qt5-gtk-platformtheme amd64 5.9.5+dfsg-0ubuntu2 [117 kB]                                       
Get:14 bionic/main amd64 qttranslations5-l10n all 5.9.5-0ubuntu1 [1,485 kB]                                                     
Fetched 9,896 kB in 38s (263 kB/s)                                                                                                                                 
Selecting previously unselected package libdouble-conversion1:amd64.
(Reading database ... 179318 files and directories currently installed.)
Preparing to unpack .../00-libdouble-conversion1_2.0.1-4ubuntu1_amd64.deb ...
Unpacking libdouble-conversion1:amd64 (2.0.1-4ubuntu1) ...
Selecting previously unselected package libqt5core5a:amd64.
Preparing to unpack .../01-libqt5core5a_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking libqt5core5a:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package libqt5dbus5:amd64.
Preparing to unpack .../02-libqt5dbus5_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking libqt5dbus5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package libqt5network5:amd64.
Preparing to unpack .../03-libqt5network5_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking libqt5network5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package libxcb-xinerama0:amd64.
Preparing to unpack .../04-libxcb-xinerama0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-xinerama0:amd64 (1.13-2~ubuntu18.04) ...
Selecting previously unselected package libqt5gui5:amd64.
Preparing to unpack .../05-libqt5gui5_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking libqt5gui5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package libqt5widgets5:amd64.
Preparing to unpack .../06-libqt5widgets5_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking libqt5widgets5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package libqt5opengl5:amd64.
Preparing to unpack .../07-libqt5opengl5_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking libqt5opengl5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package libqt5printsupport5:amd64.
Preparing to unpack .../08-libqt5printsupport5_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking libqt5printsupport5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package libqt5x11extras5:amd64.
Preparing to unpack .../09-libqt5x11extras5_5.9.5-0ubuntu1_amd64.deb ...
Unpacking libqt5x11extras5:amd64 (5.9.5-0ubuntu1) ...
Selecting previously unselected package libsdl1.2debian:amd64.
Preparing to unpack .../10-libsdl1.2debian_1.2.15+dfsg2-0.1_amd64.deb ...
Unpacking libsdl1.2debian:amd64 (1.2.15+dfsg2-0.1) ...
Selecting previously unselected package libqt5svg5:amd64.
Preparing to unpack .../11-libqt5svg5_5.9.5-0ubuntu1_amd64.deb ...
Unpacking libqt5svg5:amd64 (5.9.5-0ubuntu1) ...
Selecting previously unselected package qt5-gtk-platformtheme:amd64.
Preparing to unpack .../12-qt5-gtk-platformtheme_5.9.5+dfsg-0ubuntu2_amd64.deb ...
Unpacking qt5-gtk-platformtheme:amd64 (5.9.5+dfsg-0ubuntu2) ...
Selecting previously unselected package qttranslations5-l10n.
Preparing to unpack .../13-qttranslations5-l10n_5.9.5-0ubuntu1_all.deb ...
Unpacking qttranslations5-l10n (5.9.5-0ubuntu1) ...
Setting up libxcb-xinerama0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libdouble-conversion1:amd64 (2.0.1-4ubuntu1) ...
Setting up libsdl1.2debian:amd64 (1.2.15+dfsg2-0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up qttranslations5-l10n (5.9.5-0ubuntu1) ...
Setting up libqt5core5a:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up libqt5dbus5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up libqt5network5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up libqt5gui5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up qt5-gtk-platformtheme:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up libqt5x11extras5:amd64 (5.9.5-0ubuntu1) ...
Setting up libqt5widgets5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up libqt5printsupport5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up libqt5opengl5:amd64 (5.9.5+dfsg-0ubuntu2) ...
Setting up libqt5svg5:amd64 (5.9.5-0ubuntu1) ...
Setting up virtualbox-6.0 (6.0.4-128413~Ubuntu~bionic) ...
Adding group `vboxusers' (GID 128) ...
Done. failed: modprobe vboxdrv failed. Please use 'dmesg' to find out why.

There were problems setting up VirtualBox.  To re-start the set-up process, run
as root.
Processing triggers for libc-bin (2.27-3ubuntu1) ...

I tried to follow the suggestion:

$ sudo /sbin/vboxconfig Stopping VirtualBox services. Starting VirtualBox services. Building VirtualBox kernel modules. failed: modprobe vboxdrv failed. Please use 'dmesg' to find out why.

There were problems setting up VirtualBox.  To re-start the set-up process, run
as root.

Despite the errors, I tried to launch VirualBox and UI will launch but there was an error message in Terminal:

$ virtualbox
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (x.x.x-xx-generic) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /sbin/vboxconfig

         You will not be able to start VMs until this problem is fixed.

Solution accepted as the best answer for this SO question worked for me:

Creating Machine Owner Key Pair

$ sudo -i
root@bobox:~# whoami
root@bobox:~# mkdir /root/module-signing
root@bobox:~# cd /root/module-signing/
root@bobox:~/module-signing#  openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=YOUR_NAME/"
Generating a 2048 bit RSA private key
writing new private key to 'MOK.priv'
# chmod 600 MOK.priv

Enrolling MOK

root@bobox:~/module-signing# mokutil --import /root/module-signing/MOK.der
input password: 
input password again: 

root@bobox:~/module-signing# reboot

Upon reboot I followed the instructions:

Upon reboot I checked that my certificate has indeed been loaded:

$ dmesg|grep 'EFI:'
[    1.270214] Loaded UEFI:db cert 'Dell Inc. UEFI DB: 5ddb...' linked to secondary sys keyring
[    1.270232] Loaded UEFI:db cert 'Microsoft Corporation UEFI CA 2011: 13ad...' linked to secondary sys keyring
[    1.270246] Loaded UEFI:db cert 'Microsoft Windows Production PCA 2011: a929...' linked to secondary sys keyring
[    1.272543] Loaded UEFI:MokListRT cert 'YOUR_NAME: 9b92...' linked to secondary sys keyring
[    1.272692] Loaded UEFI:MokListRT cert 'Canonical Ltd. Master Certificate Authority: ad91...' linked to secondary sys keyring

Signing VirtualBox kernel files

Difference between .o and .ko file

root@bobox:~# cd /root/module-signing/
root@bobox:~/module-signing# ls
MOK.der  MOK.priv
root@bobox:~/module-signing# nano
root@bobox:~/module-signing# ls
MOK.der  MOK.priv

root@bobox:~/module-signing# cat 

for modfile in $(dirname $(modinfo -n vboxdrv))/*.ko; do
  echo "Signing $modfile"
  /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 \
                                /root/module-signing/MOK.priv \
                                /root/module-signing/MOK.der "$modfile"

root@bobox:~/module-signing# chmod 700
root@bobox:~/module-signing# ./ 
Signing /lib/modules/4.15.0-47-generic/misc/vboxdrv.ko
Signing /lib/modules/4.15.0-47-generic/misc/vboxnetadp.ko
Signing /lib/modules/4.15.0-47-generic/misc/vboxnetflt.ko
Signing /lib/modules/4.15.0-47-generic/misc/vboxpci.ko


Load VirtualBox driver:

$ modprobe vboxdrv

VirtualBox launched from terminal shows no errors:

$ virtualbox

I also tested running Docker container on the same machine (while running VirtualBox VM with Win 10) and it worked fine:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

For more examples and ideas, visit:

No comments: