Installing VirtualBox Guest Additions from a Linux Host

closeThis post was published 2 years 3 months 6 days ago which may make its actuality or expire date not be valid anymore. This site is not responsible for any misunderstanding.

Installing VirtualBox Guest Additions on a Linux host is a straight-forward task which can make life much easier on a guest operating systems, or OS. The Guest Additions install is the equivalent of installing VMWare Tools on a VMWare host (onto a VMWare guest OS). I’ll discuss the enhancements of installing the VirtualBox Guest Additions, and will run you through the installation process.

A Little Background Information

Try going out there on Google or any other search engine and search for information on installing VirtualBox Guest Additions on Linux. You will find plenty of information on this, so what’s the problem? Under normal circumstances, this wouldn’t be an issue, however, I like to try to be able to do everything in Linux through the command line. I hate when you have to rely on X11 or Gnome dependencies. You should be able to do anything from the command line, and if you can’t, then I try to implement some sort of my own solution (shell script, etc) to achieve this. So, with this being said, this article is geared towards not having a GUI installed. That’s the problem! If you actually search for installing the VirtualBox Guest Additions on Linux, you will get plenty of information on installing onto Linux via the GUI whether it is a Windows or Linux host OS. You know, the whole Devices » Install Guest Additions... way of mounting the ISO to the guest OS (via the host OS), and then running the install via the command line. We are going to be installing and obtaining the ISO all via the command line; no Linux/Windows GUI required.

Note: I am testing this on a CentOS Host OS and a Crunchbang Linux (Ubuntu branch-off) guest OS.

Why do I need the Guest Additions?

Well, for starters, you don’t have to install the guest additions, however, it fixes a few issues and provides additional features that you may want. The reasoning as to why I needed to install the guest additions is due to the fact that my vRDP (Virtual RDP) sessions’ mouse would not track my locally attached mouse; the calibration was totally off. This is the reason that I needed to install the guest additions, however, there are many other reasons you should. Also, as a side note, you normally install the Guest Additions on a graphical OS, as this is where your features come in and when you use a mouse, etc. Normally if you are running a guest OS in text mode, then you probably won’t even need to bother with this, since your connected via SSH, or some other form of remote connection. Let’s highlight the enhancements of installing VirtualBox Guest Additions (at this time version 3.0.8).

Another note, these set of enhancements come from the user manual, explaned in my own words. Additionally, they (the writers of the VirtualBox user manual) focus heavily on users that use the GUI (Windows or Linux client), so some enhancements may refer to this, and I’ll try to highlight points related to not using the GUI client, however, I will also explain how the GUI is enhanced, too.

Mouse Pointer Integration

This is the reason I needed to install VirtualBox Guest Additions. A mouse driver is installed that communicates to the locally attached mouse, which in turn let’s you used one mouse, therefore, there is no latency or track issues between the two. As far as the GUI is concerned, you no longer have to press the host key to get out of a VM; you simply just pull your mouse out of the Guest VM window, and your mouse is accessible on your local computer again.

Better Video Support

Additional video drivers are installed to the guest OS, which allows for further customization of video settings in the guest OS. Additionally, using the GUI, will allow you to resize the GUI window, and your guest OS screen resolution will compensate and adjust automatically. Another thing that I noticed, that worked for me, was this feature worked, out of the box. After installing the Guest Additions, my vRDP session was full screen. Before the install, I would be able to go full screen with the mstsc (Microsoft Terminal Service Client), however, there would be a very huge border around the guest OS, wasting alot of screen real estate. Once installed, the whole vRDP session became my screen, allowing for a more enjoyable experience.

Time Syncronization

This one should speak for itself. This allows the guest OS to sync with the host’s time and keep it up to date at regular intervals.

Shared Folders

This feature allows a directory on the host server to be shared, so that the guest OS can access the shared folder as a network share. This can be very useful when needing to access multiple files across multiple guest OS’s without having to copy each file to each VM. All of the files can be centrally located on the host OS, and accessible to each VM individually.

Seamless Windows

This is a pretty neat feature that is only useful if you are using the GUI. It allows your application windows in your guest OS to appear that your applications are running on the host machine.

Shared Clipboard

This one is also self-explainatory. While using the GUI, you can share the clipboard between the guest OS and the host OS. So, you can copy/paste between the two environments. This is an awesome feature if you are copy/pasting commands or configuration details.

Automatted Windows Logins

While I won’t go into detail, and would never enable this, you can have VirtualBox configured to automatically login to Windows systems. This is, obviously, a Windows-only feature.

So, now that we covered the features, let’s get to the installation.

Installation

Installation is fairly easy. First, we are going to obtain the ISO from the host OS, install dependencies for the Guest Additions install, and then we are going to actually do the install.

Obtain/Mount the Guest Additions ISO

If you are running Windows, then you should be able to obtain the ISO very easy with a quick search or by paroosing through the program files. Also note, this article doesn’t cover any Windows details. On the Linux host OS, you can easily obtain the ISO. The ISO file can be found in the installation root of your VirtualBox installation. This is normally installed in /opt/VirtualBox, however, on some hosts, it can be found in /usr/share/virtualbox/. In the installation directory, you should find a file called VBoxGuestAdditions.iso. The host OS allows you to use the VBoxManage command to attach the OS from the host OS to the guest OS. First, we have to register the ISO file (if not already), and then we will need to attach the ISO file to the guest OS. Note: Remember to run this on the Host OS, not the Guest OS.

HostOS:~# VBoxManage registerimage dvd /usr/share/virtualbox/VBoxGuestAdditions.iso
HostOS:~# VBoxManage controlvm "GuestOS" dvdattach /usr/share/virtualbox/VBoxGuestAdditions.iso
VirtualBox Command Line Management Interface Version 3.0.8
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

Note: Also, remember, above path must match the path on the host. Don’t just copy/paste my example.

Once this is complete, we can now mount the ISO to the guest OS (not just the guest VM). This is done by using the mount command as you would normally run if you inserted a CD/DVD into a physical system and mount it accordingly.

user@GuestOS:~$ sudo mount /dev/cdrom  /mnt/
[sudo] password for user:
mount: block device /dev/sr0 is write-protected, mounting read-only

Verify Media

Next, make sure that your mounted media is the correct ISO, and has the files to install the VirtualBox Guest Additions. You should see some files like mine below.

user@GuestOS:~$ cd /mnt/
user@GuestOS:~$ ls /mnt/
32Bit        VBoxLinuxAdditions-amd64.run    VBoxWindowsAdditions.exe
64Bit        VBoxLinuxAdditions-x86.run      VBoxWindowsAdditions-x86.exe
AUTORUN.INF  VBoxSolarisAdditions.pkg
autorun.sh   VBoxWindowsAdditions-amd64.exe

Actual Installation

We are almost there! Now, let’s install the build-essential packages (Ubuntu) and required dependencies (RPM-based systems), so that we have smooth sailing with the install.

Ubuntu/Debian Variant (Ubuntu, Debian, Crunchbang)

user@GuestOS:/mnt$ sudo apt-get update
user@GuestOS:/mnt$ sudo apt-get install build-essential

RPM Variant (Fedora, CentOS, RHEL)

user@GuestOS:/mnt$ yum update
user@GuestOS:/mnt$ yum install gcc kernel kernel-devel

Note: If this is a new base (OS) install, especially on RPM-based variants, you might have to boot into the new kernel to utilize the new kernel-headers.

After that’s installed, we can now install the actual VirtualBox Guest Additions. Since I’m assuming that you are running Linux, you should install the Linux version (VBoxLinuxAdditions*.run), however, you will need to install the version for your CPU architecture. If you are running 32-bit, install x86 version, and if you are running a 64-bit version of Linux, run the amd64 version. For the sake of examples, I’m running the 32-bit (x86) version.

user@GuestOS:/mnt$ sudo ./VBoxLinuxAdditions-x86.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 3.0.8 Guest Additions for Linux installation...............
VirtualBox 3.0.8 Guest Additions installation
Building the VirtualBox Guest Additions kernel module...
Building the shared folder support kernel module...
Building the drm support kernel module...
Installing the VirtualBox Guest Additions...
 
Successfully installed the VirtualBox Guest Additions.
You must restart your guest system in order to complete the installation.

Running Into Problems

If you didn’t run the build-essential install from above, you will probably run into the following errors (unless you had already done this in the past). If you do run into this issue, please run the command (sudo apt-get install build-essential) stated above.

user@GuestOS:~$ sudo ./VBoxLinuxAdditions-x86.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 3.0.8 Guest Additions for Linux installation...............
VirtualBox 3.0.8 Guest Additions installation
Please install the GNU compiler.
Problems were found which would prevent the Guest Additions from installing.
Please correct these problems and try again.

Closing Remarks

Actually installing the VirtualBox Guest Additions is quite the easy task. I’ve never actually run into any issues installing. Go ahead and restart your guest OS, and play around with the new features! Have fun!