When working with virtual machines, you’ll likely encounter the frustrating error message: “This system is currently not set up to build kernel modules” when attempting to install VirtualBox Guest Additions on Ubuntu 18.04.
This error creates a roadblock that prevents you from enjoying enhanced VM functionality like seamless mouse integration, shared folders, and proper screen resolution.
The complete error typically looks something like this:
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
VirtualBox Guest Additions: Running kernel modules will not be replaced until the system is restarted
In this comprehensive guide, I’ll explain exactly why this error occurs and provide you with multiple proven solutions based on my experience working with virtualization technologies.
Read: How to add guest features to your Virtualbox on Ubuntu 18.04
Why Does This Error Occur?
At its core, this error appears because Ubuntu 18.04 doesn’t include the necessary development tools and kernel headers by default. These components are essential because VirtualBox Guest Additions needs to build kernel modules that integrate with your specific Linux kernel.
The missing components generally include:
- Kernel headers: These are C header files that define the kernel’s internal interfaces, allowing modules to interact with kernel functions.
- Development tools: Packages like gcc (compiler), make (build utility), and perl (programming language) that are required for compiling kernel modules.
- DKMS (Dynamic Kernel Module Support): A framework that allows kernel modules to be automatically rebuilt when you install a new kernel.
Without these components, the kernel module building process will fail, preventing Guest Additions from installing correctly.
Step-by-Step Solutions to Fix the Error
Solution 1: Install Essential Build Packages
The most straightforward fix is to install the required development tools:
- Open a terminal in your Ubuntu 18.04 virtual machine.
- Update your package repositories:
sudo apt-get update
- Install the essential build packages:
sudo apt-get install build-essential gcc make perl dkms
This command installs:
build-essential
: A meta-package that includes compilation tools and librariesgcc
: The GNU C Compilermake
: The GNU build automation toolperl
: The Perl programming language interpreterdkms
: Dynamic Kernel Module Support for automatic rebuilding
- Restart your virtual machine:
sudo reboot
- After the restart, try installing Guest Additions again by clicking on “Devices” in the VirtualBox menu, then selecting “Insert Guest Additions CD image…”
Solution 2: Install Matching Kernel Headers
Sometimes, the error persists because you need to specifically install kernel headers that match your running kernel version:
- First, identify your current kernel version:
uname -r
- Install the exact matching kernel headers:
sudo apt-get install linux-headers-$(uname -r)
The $(uname -r)
part automatically expands to your current kernel version (like 4.15.0-generic), ensuring you get the correct headers package.
- Reboot your system again:
sudo reboot
Solution 3: Combined Comprehensive Approach
For persistent issues, a more thorough approach combines both previous solutions:
sudo apt-get update
sudo apt-get install build-essential gcc make perl dkms linux-headers-$(uname -r)
sudo reboot
After the reboot, insert the Guest Additions CD and run the installer:
sudo ./VBoxLinuxAdditions.run
Solution 4: Clean Installation After Removing Previous Attempts
If you’ve made multiple attempts to install Guest Additions, conflicting files might be causing issues. Here’s how to start fresh:
- Remove any existing VirtualBox guest packages:
sudo apt-get purge virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
- Check for leftover kernel modules:
ls -al /lib/modules/$(uname -r)/updates/dkms
- If you find VirtualBox-related modules, remove them manually.
- Verify that no VirtualBox packages remain:
dpkg -l *virtualbox*
- Apply Solutions 1-3 above to reinstall everything cleanly.
Verifying Your Kernel Is Ready for Module Building
After applying these fixes, you can verify that your system is properly set up for building kernel modules:
- Check if the kernel build directory exists:
ls -l /lib/modules/$(uname -r)/build
A successful setup will show a symbolic link pointing to your kernel headers directory, typically in /usr/src/linux-headers-[version]
.
- Verify that you have the essential compiler installed:
gcc --version
- Confirm that make is available:
make --version
If all these checks pass, your system should now be properly configured to build kernel modules.
Read: A Deep Dive into Linux Operating System Architecture: Components and Functions
The Role of Kernel Headers in Module Building
Kernel headers are critical for building modules because they provide the necessary interface definitions that modules need to interact with the kernel. When you install kernel headers, you’re essentially giving your system the “blueprints” that define how to connect new code to the existing kernel.
For VirtualBox Guest Additions specifically, these headers enable the creation of custom drivers that integrate with your Ubuntu system. Without properly matching headers, the module building process cannot determine how to correctly interact with your kernel.
Common Pitfalls and Troubleshooting
Kernel Version Mismatch
One common issue is when your kernel headers don’t match your running kernel version. Always verify the versions match:
uname -r # Shows running kernel version
apt list --installed | grep linux-headers # Shows installed header packages
The output from both commands should show matching version numbers.
VirtualBox Version Compatibility
If you’re using an older version of VirtualBox (like 5.2.12 mentioned in the error), consider updating to the latest version. Newer VirtualBox versions often include improved compatibility with current Ubuntu releases.
As one user reported, simply updating VirtualBox to version 5.2.22 resolved their installation issues completely.
Failed Automatic Installation
If the Guest Additions CD doesn’t automatically launch the installer when inserted:
- Locate the CD in your file manager (usually mounted at
/media/yourusername/VBox_GAs_[version]
or on your desktop) - Open a terminal in that directory and run:
sudo ./VBoxLinuxAdditions.run
- Check the installation log for errors:
cat /var/log/vboxadd-install.log
Beyond Installation: Testing Guest Additions Functionality
After successfully installing Guest Additions, verify that it’s working correctly:
- Seamless mouse integration: Your cursor should move between host and guest without requiring the host key.
- Screen resizing: The VM display should automatically adjust when you resize the window.
- Check loaded modules: Run this command to confirm the modules are loaded:
lsmod | grep vbox
You should see several modules like vboxguest, vboxsf, and vboxvideo.
Maintaining Guest Additions After Kernel Updates
The DKMS package (which we installed earlier) helps maintain your Guest Additions across kernel updates by automatically rebuilding modules. However, after major Ubuntu updates, you might need to reinstall Guest Additions.
If you notice Guest Additions features stop working after a kernel update, simply repeat the installation process.
Conclusion
The “This system is currently not set up to build kernel modules” error in VirtualBox is almost always caused by missing development tools and kernel headers in Ubuntu 18.04. By installing the necessary packages—build-essential, gcc, make, perl, dkms, and matching kernel headers—you can resolve this issue and successfully install Guest Additions.
Remember that proper kernel module building capability is essential not just for VirtualBox Guest Additions but for any third-party drivers or kernel modules you might need to install in the future.
Frequently Asked Questions
Q: Why doesn’t Ubuntu come with these packages pre-installed?
A: Ubuntu aims to provide a balance between functionality and system size. Development tools are excluded from the default installation to keep the system lightweight, as most regular users don’t need to compile software.
Q: Will I need to repeat this process after upgrading Ubuntu?
A: Possibly. Major Ubuntu version upgrades might require reinstalling Guest Additions, but the DKMS package helps maintain compatibility during minor kernel updates.
Q: What if I’m using a different Ubuntu version like 20.04?
A: The same principles apply to newer Ubuntu versions, though package versions may differ. The commands sudo apt install build-essential dkms linux-headers-$(uname -r)
should work across most Ubuntu versions.
Q: How do I know which version of VirtualBox I’m using?
A: On your host system, open VirtualBox and click on “Help” → “About VirtualBox” to see the version number.
Q: Can I install Guest Additions from Ubuntu’s repositories instead?
A: Yes, you can install them with sudo apt install virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
. However, these may not match your VirtualBox version exactly, so the CD method is usually preferred.
Q: What if the Guest Additions CD doesn’t automatically mount?
A: You can manually mount it with:
sudo mkdir -p /mnt/cdrom
sudo mount /dev/cdrom /mnt/cdrom
cd /mnt/cdrom
sudo ./VBoxLinuxAdditions.run
Q: Why do shared folders not work even after installing Guest Additions?
A: You likely need to add your user to the vboxsf group:
sudo usermod -aG vboxsf $USER
Then log out and back in for the changes to take effect.
The post How to Fix System is Not Set Up to Build Kernel Modules Error in Ubuntu appeared first on net2.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.