80

Reading the Virtualbox user manual, I finally got [here], which explains how to install Virtualbox Guest Additions on a Linux guest via Command Line.

But it's not clear enough for me (I just started learning some commands). Can someone put down the exact commands you would use to install Virtualbox Guest Additions via CLI? (which includes finding where virtualbox guest additions has been mounted etc.)

its_me
  • 13,959

8 Answers8

119

... finally this worked for me, should also work for anybody else trying to install VirtualBox Guest Additions on a CentOS (x86_64) virtual server in command line mode.

# yum update
# yum install dkms gcc make kernel-devel bzip2 binutils patch libgomp glibc-headers glibc-devel kernel-headers elfutils-libelf-devel
# mkdir -p /media/cdrom
# mount /dev/scd0 /media/cdrom
# sh /media/cdrom/VBoxLinuxAdditions.run

Note: In CentOS 7 and higher the cdrom is at /dev/sr0 instead of /dev/scd0.

When the process is complete, reboot the system. That's all.

αғsнιη
  • 41,407
its_me
  • 13,959
  • 2
    I do not think there is a need for the reboot here. Just check the vbox* modules are installed under /lib and then run modprobe for each vbox module; make sure the vbox startup scripts at /etc/init.d/vbox* are all (re)started. To just check whether the VBoxAdditions are working, I would start with testing the copy-paste between the source and vmguest. Run VBoxClient-all command and see if it returns anything. If nothing is returned VBox is setup fine. Also, check chkconfig to make sure the vbox startup scripts are properly defined to start at required runlevels. – Nikhil Mulley Nov 30 '11 at 10:24
  • 2
    I try to do the line mount /dev/scd0 /media/cdrom and I get: mount point /media/cdrom does not exist. Is there something I am missing? – theJerm Oct 31 '12 at 18:46
  • 3
    You need to yum install make as well – nic ferrier Feb 06 '12 at 12:23
  • 1
    Please also note that you must add your username to the groups: vboxsf, vboxusers (first create this one). –  Nov 11 '12 at 00:51
  • @theJerm Check this one: http://www.jacklmoore.com/notes/development (under section: VirtualBox Guest Additions) – its_me Nov 25 '12 at 06:44
  • 6
    @theJerm I hope you already figured this out, but for the record: create the mountpoint (just a directory) with sudo mkdir /media/cdrom. – Anthon Jun 10 '13 at 20:27
  • Need yum install dkms too. Was getting no output at all when running ./VBoxLinuxAdditions.run. – ficuscr Aug 30 '13 at 03:06
  • 5
    On a minimal install of CentOS 6.4 64b the install command was sh /media/cdrom/VBoxLinuxAdditions.run. I also had to install Perl (yum install perl) and create the mount-point (sudo mkdir -p /media/cdrom). – smholloway Nov 11 '13 at 16:18
  • It doesn't work for me, it asks for linux headers. – stiv Mar 30 '15 at 07:39
  • 27
    In CentOS 7 the cdrom is not at /dev/scd0 but instead at /dev/sr0 – isapir Mar 14 '16 at 04:15
  • 6
    In case people are wondering... before any of this is done, you have to use Insert Guest Additions CD image, (currently found in Devices in the virtualbox's window menu), in order for VBoxLinuxAdditions.run to be actually available. – alekosot Nov 18 '16 at 18:23
  • In addition to this, I had to do sudo yum install kernel-headers and when executing the install, KERN_DIR=/usr/src/kernels/2.6.32-504.16.2.el6.x86_64 sudo /media/cdrom/VBoxLinuxAdditions.run. EXPORTing the KERN_DIR did not work. But alas, I was able to install this. :/ – juice Dec 02 '16 at 01:45
  • 1
    If you can't mount the CD for some reason (eg: you're working over ssh), you can download an ISO of the guest additions for any version from http://download.virtualbox.org/virtualbox – jxmallett Feb 03 '17 at 03:29
  • 1
    If you need to keep your guest additions in sync when using vagrant, check out the vagrant-vbguest plugin. – jxmallett Feb 03 '17 at 04:05
  • in addition to jxmallet comment, if you can't mount the CD, then you can download the the ISO with wget e.g. wget https://download.virtualbox.org/virtualbox/5.2.18/VBoxGuestAdditions_5.2.18.iso (but choose the right version number) and then mount the iso with mount -t iso9660 -o loop VBoxGuestAdditions_5.2.18.iso /mnt/cdrom – Mark Ch Oct 01 '18 at 06:42
  • make sure you reboot after the yum update command. And remove the older kernel-devel package. – Jeetendra Pujari Feb 19 '19 at 01:55
  • But why bother at all since paste into linux console does not seem to work anyway. – sproketboy Mar 12 '21 at 14:12
16

@its_me's answer almost worked, but it failed building some kernel modules.

If it doesn't work for you, look at the messages.

In my case, one of them asked to look into /var/log/vboxadd-install.log. There it said something about missing kernel sources and to provide the kernel source directory with e.g. KERN_DIR=/path/to/kernel/sources.

Since kernel-devel and sources at /usr/src/kernels/2.6.32-504.16.2.el6.x86_64 were already installed, I was confused, but called it with the requested environment variable

KERN_DIR=/usr/src/kernels/2.6.32-504.16.2.el6.x86_64 sh /media/cdrom/VBoxLinuxAdditions.run

Now it complained about missing header files and suggested to do

yum install kernel-devel-2.6.32-504.el6.x86_64

As you can see, this is a slightly different version, 504.16.2 vs just 504. After installing the proper kernel-devel package, building and then installing worked as expected.


So, running kernel and installed kernel sources (aka kernel-devel) must match. You can verify this by looking at the running kernel with

uname -a

and the installed sources at

ls /usr/src/kernels

As a final conclusion, whatever happens, look at the messages and log files provided.

Olaf Dietsche
  • 1,637
  • 14
  • 17
  • I made the kernel sources match the kernel, by updating the kernel. yum update kernel. – Mike Sep 15 '16 at 17:42
  • 1
    If it is not matching and you just updated the kernel -> reboot to match (if you can). – A.D. Nov 02 '16 at 03:25
6

This is an old thread but came up in my search for a similar issue. In case anyone else runs into this, the following answer solved it for me:

http://www.if-not-true-then-false.com/2010/install-virtualbox-guest-additions-on-fedora-centos-red-hat-rhel/

Note* The URL says 2010 but the article was updated in 2013.

  • 3
    These steps are a lot better, because they include all of the necessary prerequisites like perl and dkms – bmaupin Sep 26 '14 at 16:07
4

I'm posting an updated answer, as because I needed to perform a few additional steps to install. I'm using VirtualBox 5.0.14r105127. Each command will have to be prepended with "sudo".

yum update
yum install gcc
yum install kernel-devel
yum install bzip2
yum install kernel-devel-2.6.32-573.el6.i686
mkdir /media/cdrom
mount /dev/scd0 /media/cdrom
sh /media/cdrom/VBoxLinuxAdditions.run

Also, I got a "FAILED" message for the OpenGL support module, but this can be ignored on a server system.

mwfearnley
  • 1,126
2

After installing the VBOXADDITIONS you might need to do this:

In VirtualBox click View>>Auto Resize Guest Display (Host + G)

because the screen resolution did not work for me until I applied this final configuration to VirtualBox.

Nidal
  • 8,956
user73362
  • 121
2

If you are using Vagrant for scripting your VirtualBox, you can simply install the vb-guest plugin. The source code for the same can be found here https://github.com/dotless-de/vagrant-vbguest/tree/master/lib/vagrant-vbguest.

Some hints can be gleamed from the source code here to automate this process.

ksinkar
  • 206
  • 2
  • 6
1

Step 1:

yum update

Step 2:

Go to Device-> Install Guest Additions CD Image -> Next

Then provide the root password . That's it.

clk
  • 2,146
Sireesh
  • 111
  • 3
0

Just a little detail ... I had a CentOS 6.6 minimal, did all the "yum update" and "yum install" but I was still stuck until I've read this in Olaf's response

... this is a slightly different version, 504.16.2 vs just 504. After installing the proper kernel-devel package, building and then installing worked as expected.

So, running kernel and installed kernel sources (aka kernel-devel) must match.

checking on my install I had the same problem, after doing a reboot, everything was ok. The machine was still running with the old kernel. After this the next problem as that perl was missing so I had to do also an

yum install perl