Setting up and configuring VirtualBox
If you've decided to use VirtualBox in your environment (either for studying, testing distributions, or evaluating network services before implementation), we will set up our VirtualBox host in this activity.
Acquiring VirtualBox
Downloading and installing VirtualBox is actually fairly straightforward, but each platform has its unique quirks. In Windows, the initial installation is simply a matter of navigating to the following site and downloading the setup file and running through the installation wizard:
https://www.virtualbox.org/wiki/Downloads
After installation, all you would need to do is skip to the Downloading and installing the Extension Pack section of this chapter. Installing on Mac OS X is also straightforward.
For Linux, there are several methods to install VirtualBox. One way is to use your package manager, if your distribution already has it available in its repositories. Unfortunately, depending on the version of your distribution, the version of VirtualBox that may be included is very likely to be out of date. For example, Debian typically contains older packages in its repositories, but bleeding-edge distributions such as Arch are more likely to contain the latest and best.
Perhaps a better way of acquiring VirtualBox is to import the repositories that VirtualBox itself provides into your system. The following URL has a list of Debian repositories and even a method of adding a repository for RPM-based distributions (Fedora, Red Hat, and so on):
https://www.virtualbox.org/wiki/Linux_Downloads
For example, using the instructions on the page as a guide, we can run through the following procedure on a Debian-based system. However, Oracle may change their instructions and repository listing at any time; always consult the previous URL before installation to see if the procedure has changed.
To verify that we will add the correct version, we need to determine which repository to use. This differs based on which distribution you're running, so definitely consult the documentation on the VirtualBox site to ensure you're importing the correct repository.
For Debian 8 "Jessie", we would use the following:
deb http://download.virtualbox.org/virtualbox/debian jessie contrib
To add this repository to our Debian system, we would use the following command:
# echo "deb http://download.virtualbox.org/virtualbox/debian jessie contrib" > /etc/apt/sources.list.d/virtualbox.list
Then, we can add the public key for the repository with the following command:
# wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | apt-key add -
From now on, we can find Oracle's VirtualBox package in our repositories and install it. To do so, let's first update our package listing with the following command (as root):
# apt-get update
Then install VirtualBox with the following command:
# apt-get install dkms virtualbox-4.3
Note
This same procedure for installation will work for Ubuntu as well, as long as you choose the appropriate matching repository.
For distributions such as Fedora, Red Hat Enterprise Linux (RHEL) and openSUSE, Oracle provides similar instructions.
The public key can be downloaded via the following command:
# wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | rpm --import -
In order to add the repository to a Fedora system, execute the following command:
# wget -P /etc/yum/repos.d/ http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo
After adding the repository, VirtualBox can be installed with the following command:
# yum install VirtualBox-4.3
In addition, instructions for OpenSUSE and RHEL are also available on the VirtualBox website. See the VirtualBox website for more details at https://www.virtualbox.org.
Downloading and installing the Extension Pack
Oracle offers an Extension Pack, which enables USB support as well as support for Preboot Execution Environment (PXE) booting. You may or may not need these features. If you think you would benefit from being able to insert a flash drive on your host PC and accessing it from within your VM, it's probably a good idea to install the pack.
Note
The extension pack isn't built-in to VirtualBox due to licensing issues. Feel free to consult the VirtualBox license should you wish to learn more.
The installation procedure for the extension pack is mostly the same, regardless of whether your host computer is running Linux, Windows, or Mac OS X. However, there is one added step if your host is running Linux, which is to add your user account to the vboxusers
group.
- When you first install VirtualBox, it should have created this group. To verify, execute the following command:
cat /etc/group |grep vboxusers
- You should see an output similar to the following:
vboxusers:x:1000:username
- If you don't see the output, create the group with the following command:
# groupadd vboxusers
- Then, add yourself to that group:
# usermod -aG vboxusers yourusername
Note
You'll need to log out and then log in before adding yourself to the vboxusers
group takes effect.
Now, you're ready to install the extension pack. Again, this procedure should be the same regardless of your underlying operating system. First, download the Extension Pack from the following URL and save it locally:
https://www.virtualbox.org/wiki/Downloads
After downloading, follow the next steps:
- Open VirtualBox and go to File | Preferences....
- Next, click on Extensions and then click on the green triangle icon on the right-hand side.
- Select the extension pack that you downloaded earlier and click on Open.
- You'll then be asked to confirm the installation. Click on Install.
- The VirtualBox license agreement will be displayed. Feel free to check it. Then, scroll to the bottom and click on I Agree to confirm it.
- If you're running Linux, you may be asked for the root or sudo password. If you do, enter it and continue. After authenticating, you should see confirmation that you've successfully installed the extension pack.
After this procedure, VirtualBox will be up and running on your machine.
Note
In some distributions, the password prompt may not appear, causing the installation of the extension pack to fail. If that happens, run VirtualBox with root privileges using the following command:
sudo VirtualBox
Then, try installing the extension pack again. Once finished, close VirtualBox and then reopen it as a normal user before continuing.