Install VirtualBox for use in GNS3

Virtualbox_logoA reader recently requested that I do a post on installing VirtualBox and integrating it into GNS3 on a Linux install, so here it is.

In this post I provide step-by-step installation details for VirtualBox 4.3.18 (the latest version available) as well as the installation of the vboxwrapper for integration into GNS3.

I will be using a clean install of Ubuntu 14.04 LTS to describe the steps. This post assumes that you already have a working install of GNS3 version 1.1 on your system. If you have not yet installed GNS3, please see my previous post GNS3 v1.1 install on Ubuntu 14.04 LTS for instructions.

The most common issues that people encounter when trying to integrate VirtualBox into GNS3 are as follows:

  1. User permission problems, VirtualBox needs to have the same permissions as the user that GNS3 uses or you will not be able to see your VM’s in GNS3.
  2. Installing the vboxwrapper for GNS3 using python3 instead of python2.7

As long as you install VirtualBox using the same user as you used to install GNS3 and use python2.7 to install the vboxwrapper, the installation is pretty straight forward.

Install VirtualBox

If you followed my GNS3 version 1.1 install on Ubuntu, then your GNS3 user will be root. Therefore we will need to install VirtualBox as root so that there are no permission issues when adding VM’s to GNS3.

Step 1: Login as Root

All commands in this post will be run as root so the first step is to login into your root account using sudo:

Step 2: Add the VirtualBox Repositories

We need to add the VirtualBox repository to /etc/apt/sources.list. This will enable us to download the latest version of VirtualBox from the VirtualBox Ubuntu Trusty Tahr repository. To do this we need to add the following to /etc/apt/sources.list:

Create a backup of you /etc/apt/sources.list file in case something goes wrong:

Using your prefered method of editing file on Ubuntu (nano, vim or vi) add the above line to the bottom of your /etc/apt/sources.list file:

Sample output:

Step3: Setup Oracle Public Key

Next we need to download the public key from Oracle, and add it to the apt sources keyring, so that we can validate the VirtualBox repository we just added:

Sample output:

Step 4: Install VirtualBox and DKMS

Now we need to update our repositories and install VirtualBox 4.3 and Dynamic Kernel Module Support (DKMS).

DKMS enables generating Linux kernel modules whose sources generally reside outside the kernel source tree. The concept is to have DKMS modules automatically rebuilt when a new kernel is installed. If you do not install DKMS at this point each time your Distribution updates its Linux Kernel you will have to rebuild the VirtualBox Kernel modules using the vboxdrv command, for more details see my previous post Ubuntu kernel update breaks Virtualbox

To install DKMS and VirtualBox 4.3 issue the following command:

At the end of the install you should see something similar to this output:

This indicates that DKMS is working and has registered the VirtualBox kernel modules successfully.

Step 5: Edit VirtualBox Application Launcher

In order to run VirtualBox as root using the VirtualBox application launcher, we need to edit the launcher to include “gksu” to start the graphical VirtualBox application as root. To do this we will use gnome panel and gksu.

Now we can use gnome panel to edit the /usr/share/applications/virtualbox.desktop file. Issue the following command to edit the virtualbox.desktop file:

Add gsku to the front of the of the VirtualBox %U command and click “Close”:

Launcher Properties_066

Now when you click on the VirtualBox application launcher you will be prompted for your password and VirtualBox will start as root.

virtualbox

Install the GNS3 vboxwrapper

GNS3 is written in python3 while the VirtualBox API and XPCOM is written in python2, because of this GNS3 and VirtualBox don’t play nicely together out of the box. As a temporary solution while waiting for VirtualBox API and XPCOM to be ported to Python3, GNS3 uses a vboxwrapper that enables GNS3 and VirtualBox to speak to each other.

In order to install the vboxwrapper you will need to have the python2.7 setuptools installed. To install the python2.7 setuptools we will use pip. First download the get-pip.py file from Git Hub:

Next execute the get-pip.py script using python2.7 install the python2.7 setuptools:

Sample output:

Now we need to download the vboxwrapper from Git Hub:

Next unzip file master.zip file and install the vboxwrapper. Note: make sure you use the python2.7 command to execute setup.py:

At the end of the installation you should see the following:

Create a VM

Next we will create a Virtual Machine that we will use in GNS3 to test everything is working. As a test I will be setting up an Ubuntu 14.04 server to add into GNS3 and connecting it to an IOU router running DHCP.

Step 1: Create a new Virtual Machine:

Oracle VM VirtualBox Manager_001

Step 2: Set the VM name and operating system type:

Create Virtual Machine_002

Step 3: Set the amount of memory to allocate to the new VM:

Create Virtual Machine_003

Step 4: Create the VM’s Virtual Hard Drive:

Create Virtual Machine_004

Step 5: Select the type of Virtual Hard Drive:

Create Virtual Hard Drive_005

Step 6: Select the method of allocating the storage of the Virtual Hard Drive:

Create Virtual Hard Drive_006

Step 7: Set the size of the Virtual Hard Drive:

Create Virtual Hard Drive_007

Step 8: Start the virtual Machine you just created:

Oracle VM VirtualBox Manager_008

Step 9: Select the image to boot the VM with and click “Start”:

Select start-up disk_009

Step 10: Install Ubuntu server as per normal:

Ubuntu Server [Running] - Oracle VM VirtualBox_010

Add the VM to GNS3

Now that we have a working VM we need to add it to GNS3 so that we can use it in our topologies.

Step 1: Click edit from the tool bar menu, and select “Preferences”:

untitled.gns3- — GNS3_001

Step 2: Select VirtualBox from the menu on the left, make sure the path to the vboxwrapper is /usr/local/bin/vboxwrapper:

Preferences_003

Step 3: Select VirtualBox VM Preferences from the menu on the left hand side and click “New”:

Preferences_068

Step 4: Select the VM from the drop down menu and click finish:

New VirtualBox VM_004

Step 5: Select the PC icon in the left hand side where you will find your newly added VM. Drag the VM into the work space:

untitled.gns3- — GNS3_008

 

Step 6: Connect the Ethernet interface of the server to the routers Ethernet interface and click start:

untitled.gns3- — GNS3_012

In this test I configured the router to act as a DHCP server with the following configuration:

So if everything is working correctly when the server boots up it will receive an IP address from the router:

Ubuntu Server [Running] - Oracle VM VirtualBox_015

Perfect, the server has learned an IP address of 10.10.10.2 and we can ping the default router 10.10.10.1. Also take note of the MAC address of the server as it should show up in the ARP table of the router:

IOU1_016

Excellent, the MAC address in the ARP table of the router matches the MAC address of the servers Eth0 interface and we can ping the server from the router so everything is working as it should be.

I hope this “How to” has been useful, as always if you have any problems with the setup please add a comment with the details and I will try my best to help.

References:

http://tecadmin.net/install-oracle-virtualbox-on-ubuntu/
http://www.howopensource.com/2013/04/install-virtualbox-ubuntu-ppa/
https://github.com/GNS3/vboxwrapper

FacebookTwitterGoogle+Share

18 thoughts on “Install VirtualBox for use in GNS3”

  1. Hi Jonathan, I followed your above instructions and I finally got the GNS3 v1.1 and Virtualbox integration working, thank you very much.

  2. Hi Jonathan, I did a fresh installation of ubuntu 14.04 and then followed your instructions to install GNS3 and VBOX (4.3.20 r96996). But now when I try to integrate them, this message pops up on GNS3:

    Could not execute VBoxManage Command
    ´[´/usr/local/bin/vboxwarepperd´,´–nologo´,´list´,´vms´]´ returned non-zero exit status 1.

    With GNS3 v1.1 and VBOX 4.18 it worked…Can you please look into this issue and advise?

    Thanks a lot.

        1. I haven’t tested the new version with Virtualbox as yet, but as far as I am aware there have been changes made to the way Virtualbox and GNS3 interact in version 1.2.

          If the Virtualbox API is now using python 3 the wrapper may no longer be required, but like I said I haven’t done any research on this as yet.

  3. @Duber in step 2 of adding a VM to GNS3 instead of using the path to the VirtualBox wrapper (/usr/local/bin/vboxwrapper) point the path to VBoxMange it should be in /usr/bin/VBoxManage but you can confirm using the whereis VBoxMange command eg.

    jonathanm@GNS3:~$ whereis VBoxManage
    VBoxManage: /usr/bin/VBoxManage /usr/bin/X11/VBoxManage
    jonathanm@GNS3:~$

    This should sort out any problems you are having. I will do an updated post on this as soon as I can :)

  4. Jonathan, I fixed…

    Now GNS3 is not using vboxwrapper but VBoxManage

    /usr/lib/virtualbox/VBoxManage

    Cheers,

    Duber

      1. @jonathan: I don’t mean to sound like an idiot here as well as being such a novice that I am , but I am stuck here:

        “Next unzip file master.zip file and install the vboxwrapper. Note: make sure you use the python2.7 command to execute setup.py:”

        I am experienced using Dos from many years ago, so I’m not too uncomfortable using the simular linux terminal and commands in Ubuntu. So for starters, my terminal is open, I’m at the root dir and see master.zip file and vboxwrapper-master directory, but I am getting stuck at pulling all 3 steps together which I would greatly appreciate you will walk me through:
        l
        (okay at this point my terminal window is open at the root dir; what do I do from here based on these steps below)

        1.Unzip masterzip file (how and where)

        2.Install the vboxwrapper (how and where) and

        3. You stated “make sure you use the python2.7 command to execute setup.py”. Okay… what is the python2.7 command and how do I apply that command to execute setup.py?

        1. If you are running GNS3 v1.2 and the latest version of Virtualbox then you no longer need to use the virtualbox wrapper as virtualbox has updated their API to use python3 instead of python2.

          GNS3 is written in python3 and previously the Virtualbox API was written in python2 therefore you required a wrapper to get the 2 to talk to each other, but since the new virtualbox uses a python3 API this is no longer required.

  5. Very well then and thank you sir! You’ve done a great job with this site and I thank you as well for invaluable help you provide for inquiring minds… I’ve been sharing links to your site everywhere.

    So far I’m running Ubuntu 14.04 LTS and GNS3 1.2.1. Are there any other tips you can give to get ahead and around of doing something I don’t need based on what I have installed? Also, are there any recommendations you can give or direct me to, to beef up what I’m running so far; for instance, other topics like you have on your site such as TFTP in Ubuntu, and or adding VPCS to GNS3. Should I work towards integrating those two as well as adding ASA or any other thing I have not mentioned that I may need?

    I was using Packet tracer, but now thanks to this beautiful version of GNS3 unlike anything they had before, I really need to have it fully functional as much as possible. However I do not know what a fully loaded GNS3 is; can you give me some idea of that as well?

    1. @Genius thanks, really glad you have found the site useful :) Wish I had more time to write posts though although with me doing my ICND2 exam at the end of the month I might be posting quite a nit as I study.

      With regards to “beefing” up GNS3, it all really depends on what you plan on using it for. If you are going to use it for your CCNA/CCNP security exams then installing ASA would be a really good idea. If you are going to look into doing you JNCIA or any other Juniper exams then setting up Olive would be useful (I wouldn’t have passed my JNCIA without GNS3). If you are planning on going the service provider route then setting IOSXRv is a must. That’s the beauty of GNS3 it can pretty much do anything you want to throw at it 😉

      The main features that I use are the IOU L2 and L3 images and Virtual box for testing between the different networks, I have lost count of the number of VM’s I have on my test server now 😉 VPCS is great if you just want to run a couple of pings between networks as it is very light weight.

      The best advice I can give you is play with it as much as possible, add as many features as you can get working, break it, fix it and break it again its the only way to learn as far as I am concerned, oh and never be afraid to ask questions 😉

  6. Yea, I would like to take the ccna in one shot, but I have to get GNS3 set first to start.

  7. Hello Jonathan,

    Tried .. deb http://download.virtualbox.org/virtualbox/debian trusty contrib

    and I got

    gns3@gns3-1:~$ deb http://download.virtualbox.org/virtualbox/debian trusty contrib
    No command ‘deb’ found, did you mean:
    Command ‘deb3’ from package ‘quilt’ (main)
    Command ‘debi’ from package ‘devscripts’ (main)
    Command ‘xdeb’ from package ‘xdeb’ (universe)
    Command ‘debc’ from package ‘devscripts’ (main)
    Command ‘dwb’ from package ‘dwb’ (universe)
    Command ‘derb’ from package ‘icu-devtools’ (main)
    Command ‘dab’ from package ‘bsdgames’ (universe)
    deb: command not found

Leave a Reply to jonathan Cancel reply