How do I install VirtualBox guest additions for CentOS 7?

5

2

How? It gives an error.

[vagrant@localhost mnt]$ sudo ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.16 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Removing installed version 5.1.16 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Building Guest Additions kernel modules.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.

[vagrant@localhost mnt]$ cat /var/log/VBoxGuestAdditions.log
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed..

[vagrant@localhost mnt]$ cat /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

Chloe

Posted 2017-04-06T01:06:58.480

Reputation: 4 502

Answers

3

vagrant init centos/7
vagrant up; vagrant halt
  • Add a CDROM to the virtual machine and select the VBoxGuestAdditions.iso file to insert in the drive.

virtual box guest additions

  • Manually add a shared folder in VirtualBox with name vagrant and path to the directory of your Vagrantfile. Vagrant doesn't set up /vagrant properly.

virtualbox shared folder

  • Edit Vagrantfile and add this to the bottom to provision the shared folder each time you start.

    config.vm.provision "shell", run: "always", inline: <<-SHELL
        mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
    SHELL
    
  • Continue with

    vagrant up
    vagrant ssh
    sudo yum update
    sudo yum install kernel-devel gcc
    exit
    vagrant halt; vagrant up; vagrant ssh
    export KERN_DIR=/usr/src/kernels/`uname -r`
    sudo mount /dev/sr0/ /mnt
    cd /mnt
    sudo ./VBoxLinuxAdditions.run
    

Chloe

Posted 2017-04-06T01:06:58.480

Reputation: 4 502

1

$ cat /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the \\
sources of your current Linux kernel. \\
Specify KERN_DIR=<directory> and run Make again.  Stop.

Your install.log file is very clear: you need to install the headers,

sudo yum update
sudo yum install kernel-headers kernel-devel

and then you may re-install VirtualBox.

MariusMatutiae

Posted 2017-04-06T01:06:58.480

Reputation: 41 321

That's not sufficient. It doesn't specify where they are, or what to set KERN_DIR to. – Chloe – 2017-04-07T05:16:44.513

@Chloe It only asks about KERN_DIR because it cannot find the headers, so it is offering the user an opportunity to specify a different location. But headers should be in place, in which case KERN_DIR will point to the default CentOS location, which is just fine. – MariusMatutiae – 2017-04-07T05:18:48.287

0

I needed to install kernel-header and kernel-devel. plus gcc to install virtualbox guest additions.

    sudo yum update
    sudo yum install kernel-headers kernel-devel
    sudo yum install gcc*

alianjum0

Posted 2017-04-06T01:06:58.480

Reputation: 1

Thanks, for me the provided solution didn't work without installing gcc. – alianjum0 – 2019-07-16T13:32:14.047

0

VirtualBox Guest Additions helper script for CentOS 7

I wrote this little helper script that does this to a fresh VM and corrects the error messsage by taking advantage of the fact that when the run script fails, it leaves a few helper binaries intact:

VBoxGuestInstall.sh

#!/bin/bash

# reference: https://www.if-not-true-then-false.com/2010/install-virtualbox-guest-additions-on-fedora-centos-red-hat-rhel/
# though this document is invalid, it does provide the dependencies and the epel repository needed.
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install gcc kms make bzip2 perl

# get rid of the currently running kernel packages and install the new ones...
yum remove kernel*`uname -r`
yum install kernel*

NEW_UNAME=$(ls /usr/src/kernels/ | grep 'el7.x86_64')
# this command is to ensure the kernel's .config reaches the source directory the 
# modules will be building against.
cp -f /boot/config-$NEW_UNAME /usr/src/kernels/$NEW_UNAME/.config

mkdir /media/VirtualBoxGuestAdditions
mount /dev/sr0 /media/VirtualBoxGuestAdditions

# this will fail, but your helper binaries will be installed
/media/VirtualBoxGuestAdditions/VBoxLinuxAdditions.run
# so we will now direct the helper binary to build for the kernel we want instead of
# the running one invalidly returned by `uname -r` inside of VirtualBox's .run binary.
/sbin/rcvboxadd quicksetup $NEW_UNAME

Moving the script

It targets the kernel you want instead of the running one, after installing all of the dependencies. Run a simple http server on localhost on your host and you can grab it over the network adapter inside of the VM. Nifty little trick before you get the guest additions installed. I use bitnami because I just had it lying around, but simplehttpd or something very similar will work, anything that can serve files:

cd ~/
wget 'http://host_machine_ip_goes_here:80/VBoxSetup.sh'
chmod +x ./VBoxSetup.sh
sudo ./VBoxSetup.sh

Robert Smith

Posted 2017-04-06T01:06:58.480

Reputation: 51