Install VirtualBox 5.2 on Debian 9 (stretch) host operating system

botond published 2018/11/02, p - 00:58 time

Content

 

Introductory

It is probably familiar to many VirtualBox virtualization system with which we can run different guest operating systems on our machine without disturbing the existing one.

Installation on Windows platforms is simple: Just download the latest installer package and start it. The wizard will guide you through the installation and is ready to use.

However, installing VirtualBox Linux on host operating systems is not that simple, in which case you need to carve things around a bit to make it work flawlessly.

In this tutorial, we will look at installing VirtualBox 5.2 on a Debian 9 Linux operating system.

Update (2019-10-30):
In the meantime, a more recent version of the description has been prepared:
Installing VirtualBox 6.0.x on a Debian 10 (Buster) host operating system

 

 

Installation

The VirtualBox installation package is also available for download on Linux systems official download page, however, it is recommended to install through the builders' repository, so you don't have to bother with future package updates, but you can update the system with packages at the same time.

As root, open the / Etc / apt / sources.list file or create a new file with /etc/apt/sources.list.d directory (whichever is more sympathetic), then add access to the VirtualBox repository:

deb http://download.virtualbox.org/virtualbox/debian stretch contrib

Save and then (as root) download the repository keys a wget command, which we immediately add APT for our luggage keychain:

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | apt-key add -

Then update the package repository with apt-get and install the Virtualbox 5.2 package from it:

apt-get update
apt-get install virtualbox-5.2

Next, install the DKMS package, which ensures that the next kernel is updated, the VirtualBox kernel packages (vboxdrvvboxnetflt and vboxnetadp) also updated:

apt-get install dkms

Installing kernel modules

VirtualBox kernel packages include a control interface for different hardware:

  • vboxdrv: This provides support for basic hardware such as processor and physical hardware
  • vboxnetflt and vboxnetadp: These provide extended network support in addition to the basic NAT network module.

Otherwise, the VirtualBox framework will start and we can create virtual machines, but they cannot be started, but the virtual machine will stop with the following error:

Kernel driver not installed (rc=-1908)

 

These kernel modules are not part of Linux distributions, but were developed by the developers of VirtualBox. Therefore, when you install the program, they need to be "built into" our kernel so that they can properly manage your computer's hardware. This build process requires kernel header packages, which are not included in a recent Debian installation, so they must be installed separately. A detailed description of this in English can be found here, the 2.3 section of which contains the relevant sections. 

 

Based on the above, let's first install the header packages exactly matching our kernel version:

apt-get --reinstall install linux-headers-$(uname -r)

(At the end of the command uname -r replaces our corresponding kernel version)

The installation command even adds additional package dependencies (I have installed packages for the 4.9.0-7-amd64 kernel):

csomaglisták olvasása... Kész
Függőségi fa építése       
Állapotinformációk olvasása... Kész
Megjegyzés: „linux-headers-4.9.0-7-amd64” kijelölése „inux-headers-4.9.0-7-amd64” regexhez
A következő további csomagok lesznek telepítve:
  linux-headers-4.9.0-7-common
Az alábbi ÚJ csomagok lesznek telepítve:
  linux-headers-4.9.0-7-amd64 linux-headers-4.9.0-7-common
0 frissített, 2 újonnan telepített, 0 eltávolítandó és 1 nem frissített.
Letöltendő adatmennyiség: 8.039 kB.
A művelet után 49,8 MB lemezterület kerül felhasználásra.
Folytatni akarja? [I/n] i
Letöltés:1 http://deb.debian.org/debian-security stretch/updates/main amd64 linux-headers-4.9.0-7-common all 4.9.110-3+deb9u2 [7.589 kB]
Letöltés:2 http://deb.debian.org/debian-security stretch/updates/main amd64 linux-headers-4.9.0-7-amd64 amd64 4.9.110-3+deb9u2 [449 kB]
Letöltve 8.039 kB 1mp alatt (5.946 kB/s)         
Selecting previously unselected package linux-headers-4.9.0-7-common.
(Adatbázis olvasása ... 131676 files and directories currently installed.)
Preparing to unpack .../linux-headers-4.9.0-7-common_4.9.110-3+deb9u2_all.deb ...
Unpacking linux-headers-4.9.0-7-common (4.9.110-3+deb9u2) ...
Selecting previously unselected package linux-headers-4.9.0-7-amd64.
Preparing to unpack .../linux-headers-4.9.0-7-amd64_4.9.110-3+deb9u2_amd64.deb ...
Unpacking linux-headers-4.9.0-7-amd64 (4.9.110-3+deb9u2) ...
Beállítás: linux-headers-4.9.0-7-common (4.9.110-3+deb9u2) ...
Beállítás: linux-headers-4.9.0-7-amd64 (4.9.110-3+deb9u2) ...

This will add all the necessary header packages to build the VirtualBox kernel modules.

We can then start the packet build:

rcvboxdrv setup
boxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.

You can also check for modules:

modprobe vboxdrv
modprobe vboxnetflt
modprobe vboxnetadp

If we did everything right, we will not get an error message.

So, basically, VirtualBox is ready to go:

Installing VirtualBox 5.2 on Debian 9 - VirtualBox Main Window

However, installing the upgrade package is still required for proper operation.

 

 

Installing an Extension Pack

For VirtualBox to work properly, you also need to install the Extension Pack provided by the developers, which provides the following key extra features:

  • USB (EHCI) controller (= USB 2+ support)
  • VirtualBox RDP support (remote desktop connection to the virtual machine)
  • Storage Encryption
  • Booting NVMe and PXE with Intel tab sets.

The latest version of the upgrade package is stored in the following file:

http://download.virtualbox.org/virtualbox/LATEST.TXT

Let's read this into a variable to make it more convenient:

friss=$(wget -qO - http://download.virtualbox.org/virtualbox/LATEST.TXT)

Then download the upgrade package:

cd /tmp
wget "http://download.virtualbox.org/virtualbox/${friss}/Oracle_VM_VirtualBox_Extension_Pack-${friss}.vbox-extpack"

Then install (as root):

VBoxManage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-${friss}.vbox-extpack

Success check:

VBoxManage list extpacks

The output for me:

Extension Packs: 1
Pack no. 0:   Oracle VM VirtualBox Extension Pack
Version:      5.2.20
Revision:     125813
Edition:      
Description:  USB 2.0 and USB 3.0 Host Controller, Host Webcam, VirtualBox RDP, PXE ROM, Disk Encryption, NVMe.
VRDE Module:  VBoxVRDP
Usable:       true 
Why unusable:

 

Conclusion

Everything is properly installed and we get a perfectly working copy of VirtualBox 5.2, which runs my Win7 system smoothly.

What is also a positive surprise for me is that it manages resources very well. I used to have Win7 on my machine and ran Debian in it, but now I use the other way around because I only use a few Windows-dependent programs, and it seems like the overall performance of the whole machine is better. When a virtual Win7 machine starts up, there are only about as many CPU and RAM consumption jumps as the virtual machine actually uses. So there is no waste. So now I can conveniently switch between Linux desktops and Win7 running in full screen mode on one of the desktops. File sharing and the shared clipboard also work nicely, as if there were just another application on the same system.

Of course, the VirtualBox guest services still had to be installed on the virtual machine in order for the running system to adapt perfectly to the circumstances. But that's about it in another description ...