Mastering Linux Network Administration
上QQ阅读APP看书,第一时间看更新

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.

  1. When you first install VirtualBox, it should have created this group. To verify, execute the following command:
    cat /etc/group |grep vboxusers
    
  2. You should see an output similar to the following:
    vboxusers:x:1000:username
    
  3. If you don't see the output, create the group with the following command:
    # groupadd vboxusers
    
  4. 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:

  1. Open VirtualBox and go to File | Preferences....
    Downloading and installing the Extension Pack

    Accessing the file menu in VirtualBox

  2. Next, click on Extensions and then click on the green triangle icon on the right-hand side.
    Downloading and installing the Extension Pack

    VirtualBox settings

  3. Select the extension pack that you downloaded earlier and click on Open.
    Downloading and installing the Extension Pack

    Extension pack selection

  4. You'll then be asked to confirm the installation. Click on Install.
    Downloading and installing the Extension Pack

    Confirmation of extension pack installation

  5. 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.
    Downloading and installing the Extension Pack

    VirtualBox license agreement

  6. 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.
    Downloading and installing the Extension Pack

    Confirmation of successfully installing the VirtualBox 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.