Building the main Guest Additions module …fail! – Debian Linux – Solution

When you attempt to VBoxLinuxAdditions.run script to install VirtualBox Guest Additions you may receive a following error message:

Building the main Guest Additions module ...fail!

Futher, investigation into a suggested log file may reveal:

/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR= and run Make again.  Stop.

The most likely cause for this error message to appear are missing compler and kernel headers matching your currently running kernel version. To fix this error run the following linux command as a root user to install all necessary prerequisites:

# apt-get install linux-headers-$(uname -r) build-essential

Once the installation is finished run your VBoxLinuxAdditions.run script again to install VirtualBox Guest Additions:

# bash VBoxLinuxAdditions.run

Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.

Building the main Guest Additions module ...done.
Building the shared folder support module ...done.
Building the OpenGL support module ...done.
Doing non-kernel setup of the Guest Additions ...done.
Starting the VirtualBox Guest Additions ...done.
Installing the Window System drivers
Installing X.Org Server 1.16 modules ...done.
Setting up the Window System to use the Guest Additions ...done.
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.
Installing graphics libraries and desktop services components ...done.