CSIA 430 Linux Administration – Oracle VirtualBox Guest Additions for Sharing Files with Host

Virtual Box provides a way to share files between the host OS and the virtual machine using a shared folder. Files placed inside this folder will be visible and accessible to both the host and the virtual machine. Setting up the shared folder should be a simple process, but with some versions of VirtualBox there are some things that can go wrong and cause problems. This page covers the setup process as well as some troubleshooting tips.


Process for Setting Up Guest Additions – Desktop

This process has a few parts, downloading the correct version of Guest Additions, preparing the Linux server, installing Guest Additions, and configuring the shared folder and shared clipboard.

Note – make sure that you follow the instructions and download the correct version of Guest Additions as directed in the instruction. There are many different versions, and while all of them allow you to share folders, only a few allow you to use the shared clipboard.

  1. Download the correct Guest Additions ISO. Every version of Virtual Box comes with a different version of Guest Additions, however only a few versions will provide you with the capability to copy and paste between the host computer and the VM. I’ve tested many different versions of Guest Additions and found that the following version provides both shared folders and the shared clipboard.
  2. Install the packages required to add the Guest Additions device drivers to the kernel.
    • Ensure that you’re logged in to the Linux VM, and in an account with root privileges.
    • Type the following commands to install and update the required packages:
      • [root]# yum install epel-release
      • [root]# yum update
      • [root]# yum install gcc kernel* dkms make bzip2 perl
    • Restart the Linux VM
    • Type the following command to create an environmental variable required by the Guest Additions install process
      • [root]# export KERN_DIR=/usr/src/kernels/uname -r
  3. Start the Guest Additions installation by:
    • Virtually inserting the CD with the Guest Additions ISO in the VMs optical drive. This is done by selecting Devices/Optical Drives/Choose Disk Image from the Virtual Box menus at the top of the VM Window. Navigate to the where you stored the Guest Additions ISO, and select it.
    • Select RUN when prompted about starting the autorun program on the CD/ISO image.
  4. Shutdown the Linux VM and configure the Shared Folder and Shared Clipboard in VirtualBox Manager by doing the following:
    • Open Virtual Box Manager, so that you can see your list of virtual machines. Don’t start the virtual machine, just open Virtual Box.
    • Left click the server you want to share the folder with so that the server is selected or highlighted. Once again, don’t start the virtual machine, just select it.
    • Click the Settings button in Virtual Box. This will open the Settings dialog box.
    • Click General in the left hand menu, and the select the Advanced tab.
    • Set Shared Clipboard to Bi-Directional
    • Click the Shared Folders button in the left column. This will display the Shared Folders settings and a list of shared folders. Since you haven’t shared any folders yet the list will be blank.
    • Click the Add a New Shared Folder icon. This is the icon that looks like a small folder with a green plus sign. It’s over on the right, next to the column headings. This will open the Add Share dialog box.
    • Click on the drop down symbol on the right of the Folder Path box. This will allow you to browse to the location where you want to place your shared folder. If you already have a folder you want to use, navigate to it and select it. If you want to create a new folder, navigate to the directory where you want to place the folder, right-click in the dialog box, create the folder, and then click Select Folder.
    • Ensure that the Auto-mount box is checked.
    • Click all of the the OK buttons that you see until you get back to the Virtual Box Manager. At this point the Virtual Box configuration should be complete.
  5. The shared folder(s) and shared clip board should now be active the next time you start the Linux VM.

If you experience problems or issues here are some additional references that may help. If these links are no longer active you try doing your own Internet search.

  1. Youtube Video
  2. Written Instructions
  3. Written Instructions 2 – Make sure and use the Centos version of each instruction
  4. https://www.virtualbox.org/manual/ch04.html – The VirtualBox reference page for Guest Additions

Process for Setting Up Guest Additions – Command Line

Setting up Guest Additions from the command line requires mounting the CD/DVD, and then running the install command. This is done using the following commands:

[root]# mount -r /dev/cdrom /media

[root]# cd /media

[root]# ./VBoxLinuxAdditions.run

Troubleshooting Guest Additions

Ok … if your Guest Additions installation had/has errors there are several things that may have gone wrong. I have fixes for several issues, hopefully yours is included, but I’m sure there are other problems that may occur. You’ll have to decide which of the issues you had to decide which fix to try. Hopefully there’s enough information included to help you do this. Also, you’ll be dealing with packages, which is the Red Hat/Centos way of installing software, and using commands like yum and rpm. You’ll learn all about packages in a later section, but for now you’ll need the commands to accomplish some of these tasks.

Running The Guest Additions Installer (Removing and Inserting the Guest Additions CD)

The first thing I’m going to show you how to “fix” is running the Guest Additions installation process a second or third time. If you’re new to Oracle Box this may not be obvious. The simplest way to do this is to remove the CD and then reinsert it. But since it’s a virtual CD this process isn’t obvious. To eject the CD right-click on the Guest CD window on the Linux desktop and select eject. Once it’s ejected you can run it again by going back to the Virtual Box menu and selecting Devices > Insert Guest Additions CD Images. This should start it running again.

Upgrading Virtual Box

The first fix I’m going to suggest is upgrading Virtual Box to the latest version. This is mainly if you’re in one of my CBC classes and you’ve downloaded a version of Virtual Box from Canvas or from the CBC Computer Science O: network drive. These versions are probably pretty stale, so you should try getting a newer version directly from the Virtual Box site. If you downloaded your Virtual Box from the Virtual Box site then this step is definitely not necessary. But the Guest Additions installer also seems to be looking for certain versions of the files used to rebuild the kernel, so newer versions of Virtual Box will have a newer version of the Guest Additions installer, which should be looking for the newer versions of the kernel files.

If you do decide to upgrade Virtual Box you might also want to consider using the Windows Installer to uninstall the old version prior to installing the new version. This step is probably not necessary, but it only takes an extra minute or two. Oh, and don’t worry about your actual virtual machines if you do the upgrade. They should all still be there after you finish the upgrade.

Upgrading Just Guest Additions

If you don’t want to upgrade all of VirtualBox for some reason, you also have the option of just getting a new version of just Guest Additions. You can find the 6.1.8 Guest Addition ISO image at the 6.1.18 Virtual Box download page. Or you can grab 6.1.16 from this page at Oracle.

https://www.oracle.com/virtualization/technologies/vm/downloads/virtualbox-downloads.html – the download page for 6.1.16

http://download.virtualbox.org/virtualbox/6.1.18/ – the download page for 6.1.18

Installing Packages Required to Install Guest Additions

During the Guest Additions installation you may get a message that says the installation process requires several packages including: gcc make perl kernel-devel (and possibly some others)

If this happens, you need to run the yum command to install the listed packages. For example:
[root]# yum install epel-release

[root]# yum update

[root]# yum install gcc kernel* dkms make bzip2 perl

Make sure that you do this as root, either from the root account or by using sudo. If you get errors saying that the repositories can’t be reached make sure and check your network connection to ensure that is says connected.

You also don’t have to load all of the packages at the same time using the same yum command. You can accomplish the same thing by using multiple yum commands using something like:
[root]# yum install gcc
[root]# yum install kernel-devel
[root]# yum install kernel-headers
[root]# yum install dkms

Next, restart the Linux server

[root]# KERN_DIR=/usr/src/kernels/`uname -r`

[root]# export KERN_DIR

I’ve seen several occasions when one of the packages fails to load. This is kernel-devel-3.10.0-693.el7.x86_64. This package is crucial as it contains some of the source code for the kernel, so there’s no way to proceed without it. If you encounter this try the kernel dev fixes or using ftp to install the package.

If you want to know what’s going on, and why Guest Additions needs these packages here’s a quick explanation. Guest Additions needs to install some new drivers to work. And remember that installing a driver in Linux means more than just copying a driver file. In Linux, the code for the Linux OS has to be modified by adding the new driver code to the actual source code. The OS code then needs to be recompiled, and the system restarted to use the new driver. Making these types of modifications will require some extra tools, which come in some of the packages that you will probably need to install.

So if you think of the Linux OS as just another program you needed to edit and modify this will hopefully start to make sense. And if I told you that you had to edit and recompile a Windows program how would you do it? You’d need to load some kind of editor such as Visual Studio, and you’d also need the program file(s) with the code that you cold edit. On Linux, the packages like gcc (gnu c compiler) and make contain the tools that are used to compile programs, while the packages starting with kernel contain the source code and other files you need to build a new kernel. Oh, if you’re confused by what we mean by kernel, it’s the main Linux OS code.

The code in the VBoxLinuxAdditions.run file contains some shell script command that should do everything needed to rebuild the kernel, assuming all of the packages are in place. But I’m adding a note about setting up one environmental variable, just in case it doesn’t get set by the script. This variable points to the directory that holds the kernel source files. If you set this up from the command line be very careful about the quotes and back ticks. If you don’t know what you’re doing and use the wrong quotes you will create quite a mess.
[root]# KERN_DIR=/usr/src/kernels/`uname -r`
[root]# export KERN_DIR

If all of the packages load successfully then you should try running the Guest Additions install program again. The easiest way to do this is to eject the CD and insert it again. Or, you can open a terminal window and start the program from the command line. The name of the command you want to run is VBoxLinuxAdditions.run This is on the Guest Additions CD, so you have to go to the directory where the CD has been mounted to run the command, or else put in the full path. If the CD has not been mounted, you’ll also need to mount it first. The following commands will mount CD.
[root]# mkdir /media/VirtualBoxGuestAdditions
[root]# mount -r /dev/cdrom /media/VirtualBoxGuestAdditions

The CD should now be mounted on the /media/VirtualBoxGuestAdditions directory. You can use the cd command to move there, and then run the VBoxLinuxAdditions.run command by using:
[root]# cd /media/VirtualBoxGuestAdditions
[root]# ./VBoxLinuxAdditions.run

Fixing the missing kernel-devel-3.10.0-XXX.el7.x86_64. package problem

One of the problems that I frequently see is that the Guest Additions installation code has difficulties seeing the package kernel-devel-3.10.0-XXX.el7.x86_64 where is XXX is a 3 digit version number, so something like kernel-devel-3.10.0-693.el7.x86_64. This is a minor version number for the kernel and it changes very frequently, sometimes on a weekly basis. The Guest Additions installer seems to be looking for a specific version of this package, and if doesn’t see that specific version it stops the install process. If you installed and/or updated the packages as instructed above you will have the newest version of this package, but it may not be the version Guest Additions is looking for; especially if you have an older version of Guest Additions. After you work with Virtual Box for a bit you’ll see that Virtual Box also has frequent updates, and Guest Additions is part of Virtual Box so it’s also getting frequent updates. So it seems that if you have an older version of Virtual Box and Guest Additions, it will be looking for an older version of kernel-devel-3.10.0-XXX.el7.x86_64 and will have problems if you have a newer version.

One of the ways to solve the problem with the Guest Additions installer is to get the latest version of the Guest Additions (GA) software. You can download GA independently from Virtual Box, but this is kind of a pain. The easiest way to get the latest version of Guest Additions is to update Virtual Box. You may have to uninstall the current version and then download and install the latest version. Don’t worry about your virtual machines when you uninstall Virtual Box, they should remain in place and be available when you start the new version of Virtual Box. After you update Virtual Box try running the GA installer again. Hopefully this will have solved the problem.

If the Guest Additions installer still stops because of problems with kernel-devel-3.10.0-XXX.el7.x86_64 you can manually install the specific package that GA is looking for. To accomplish this you have to first use yum to remove the current package. The reason for this is that yum wants you to have the latest version of any package, so if you’re trying to install an older version of kernel-devel-3.10.0-XXX.el7.x86_64 then you have to remove the newer version first. Typing out the entire package name can be a little difficult, so take advantage of the fact that yum understands wildcards in the package names by typing something like:

yum remove kernel-devel-3.10*

You can then use yum to load the version of the package that Guest Additions is looking for, but in this case you’ll have to use enough of the package name to get the correct version number. That is, if Guest Additions says it’s looking for kernel-devel-3.10.0-693.el7.x86_64 then you’ll have to type something like:

yum install kernel-devel-3.10.0-693*

Installing Errant Packages From a Specific Repository

While yum makes it very easy to install software, it also hides a lot of details, so when things don’t work it can be hard to fix. There are several videos in the next section on yum if you want to know more about how it works, but for now here’s a the way to install a package if yum has trouble getting it for some reason. This process has a couple of steps. First you have to find the location of the package, that is the URL of the package. And then you’ll use an older package manager called rpm (redhat package manager) to download and install the package.

Yum is actually considered easier to use than rpm because it allows you to install a package just by knowing the package name. You don’t need to know where the package is actually located on the Interwebs. With rpm, you have to find the URL for the package and provide that to rpm; which is what you’ll learn how to do next.

The first step is finding the URL for the package you want rpm to install. Finding the URL requires knowing the name of the package, which in this case we’ll get from the Guess Additions error message. The problem package seems to be kernel-devel-3.10.0-693.el7.x86_64, but the kernel version number will likely be different as this article ages. I’m going to use this package in the example , but you should double check the package name and version number before doing this yourself.

Once you have the package name, the next step is to open a browser and search for this package. The easiest way to do this is to copy the URL from the window that opened when the Guest Additions installer opened, and then paste it into the browser. (Hopefully the browser on your Centos/Linux virtual server is running. If not, you you can copy the text from the Linux virtual server and paste it in a browser in the Windows host; but only if you turned on the ability to copy and paste between the host OS and the virtual OS.) The search should bring up quite a few results, but you’re looking for a web site that has links to the package file. I know that the pbone web site has this list, so I usually go that site in the search results.

If you mouse over the list of mirror servers on the pbone page you will see the URL for the package file in the browser’s status bar which is usually shown in the lower left of the window. This URL is the information that you want, and need to provide to rpm. The easiest way to get the URL without writing it down, is to right click on one of the mirror links and select Copy Link Address. As an example, I’m going to say that the URL from the mirror link I selected is ftp://ftp.scientificlinux.org/linux/scientific/7.4/x86_64/os/Packages/kernel-devel-3.10.0-693.el7.x86_64.rpm. You can see that this is probably a lot easier to copy using this method as opposed to trying to write the URL.

Once you have the package URL, you can use rpm to fetch and install the package. This is done by using the rpm command with the -Uvh arguments, followed by the package URL. Open a terminal window, (make sure you’re running as root) and type:
[root]# rpm -Uvh ftp://ftp.scientificlinux.org/linux/scientific/7.4/x86_64/os/Packages/kernel-devel-3.10.0-693.el7.x86_64.rpm

Hopefully rpm will be able to install the package, but we have seen some instances where rpm, and yum, think the package is already installed even though Guest Additions doesn’t see the package. That is, rpm and yum will tell you that the package installed, but Guest Additions still tells you it’s not there. Or, rpm may see that the version of the installed (but unseen) package is newer than the one you’re trying to install. The fix for either one of these problems is to use yum to remove the package, and then run the rpm again to re-install it.
[root]# yum remove kernel-devel-3.10.0-693.el7.x86_64.rpm
[root]# rpm -Uvh ftp://ftp.scientificlinux.org/linux/scientific/7.4/x86_64/os/Packages/kernel-devel-3.10.0-693.el7.x86_64.rpm

Remember that your package names will probably be different, and the easiest way to get this into yum is to copy and paste it from the error message(s).

References: