Page -> Vnx-create-vagrant-vm Views :  Page  Discussion  View source  History 

From VNX

How to create a Ubuntu Vagrant virtual machine to run VNX virtual scenarios

This procedure describes how to use Vagrant to create a Ubuntu 14.04 virtual machine to run VNX. This is probably the easiest way to test VNX over Linux, Mac OSX or Windows. You can download the VM created with this procedure from here.

The VNX scenarios started within the VM created are restricted to LXC, due to limitations in nested virtualizacion (KVM virtual machines cannot be started whitin a Virtualbox virtual machine).

Create the Vagrant VM

To create a VNX ready Vagrant virtual machine, follow this procedure:

  • Install Vagrant and VirtualBox in your system (see Vagrant installation instructions for more details). For example for debian-like Linux:
  • apt-get install virtualbox vagrant
    vagrant plugin install vagrant-vbguest
  • Download Vagrant Ubuntu 14.04 basic image from Ubuntu cloud repository:
  • vagrant box add trusty32
  • Create vagrant directory and config file:
  • mkdir vnx
    cd vnx
  • Download Vagrantfile and files (see the content below)
  • wget -N{Vagrantfile,Vagrantfile.pkg,}
    chmod +x
  • Start VM for the first time (it will take several minutes to do all the package installation and configuration tasks):
    • VM without GUI:
      vagrant up
    • VM with GUI:
    • sed -i -e 's/vb.gui = false/vb.gui = true/' Vagrantfile
      GUI=yes vagrant up
  • Access the VM from the GUI and open a terminal or connect though SSH using:
  • vagrant ssh
  • Test simple VNX scenario:
  • cd /usr/share/vnx/examples/
    sudo vnx -f simple_lxc_ubuntu.xml -v -t
  • Install any aditional software or files you like and stop the VM:
  • sudo halt

Convert the Vagrant VM to a base image (.box)

To create a Vagrant base box starting from the VM created:

  • Optionally, try to reduce the VM image by writting zeros to free disk space. From inside the VM, type:
  • sudo dd if=/dev/zero of=/EMPTY bs=1M
    sudo rm -f /EMPTY
  • Get the name of the VM from VirtualBox with:
  • VBoxManage list vms
    "vnx_1402744959" {e46a72f4-2b47-4220-b77c-7a58ae98b6d1}
  • Then package that VM with:
  • vagrant package --base vnx_1402744959 --output --vagrantfile Vagrantfile.pkg
  • Optionally, copy the file created ( to a web server to allow creation of VM from this Vagrant base image.

Create a VM starting from the base image

To download and create a VM from the Vagrant base image created, just:

vagrant box add vnx
mkdir vnx
cd vnx
vagrant init vnx
vagrant up

Optionally, you can customize the VM (memory assigned or the number of cpus) by editing Vagrantfile. For example, to increase memory to 2Gb and the number of CPUs to 4, add the following lines:

   config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id,
                  "--memory", "2048",
                  "--cpus", "4"]

Vagrantfile content

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config| = "trusty32"
  config.ssh.forward_x11 = true
  config.vm.provision :shell, :path => ""
  config.vm.provider :virtualbox do |vb|
    vb.gui = false
    vb.customize ["modifyvm", :id, 
                  "--memory", "1024",
                  "--cpus", "2"]
end file content

#!/usr/bin/env bash

# VNX installation script for Vagrant VMs
# Author: David Fernández (
# This file is part of the Virtual Networks over LinuX (VNX) Project distribution. 
# (www: - e-mail: 
# Departamento de Ingenieria de Sistemas Telematicos (DIT)
# Universidad Politecnica de Madrid


echo "-- Installing VNX:"

echo ""
echo "---- Changing hostname:"
echo ""

echo $HOSTNAME > /etc/hostname
hostname $HOSTNAME
sed -i -e '/^' /etc/hosts
sed -i -e '/^{:a;n;/^$/!ba;i\\t$HOSTNAME' -e '}' /etc/hosts
#sed -i -e "s/*/   $HOSTNAME/" /etc/hosts

echo ""
echo "---- Installing required packages:"
echo ""

apt-get update
apt-get -y dist-upgrade
apt-get -y install qemu-kvm libvirt-bin vlan xterm bridge-utils screen virt-manager \
  virt-viewer libxml-checker-perl libxml-parser-perl libnetaddr-ip-perl libnet-pcap-perl \
  libnet-ipv6addr-perl liberror-perl libexception-class-perl \
  uml-utilities libxml-libxml-perl libterm-readline-perl-perl libnet-telnet-perl \
  libnet-ip-perl libreadonly-perl libmath-round-perl libappconfig-perl \
  libdbi-perl graphviz genisoimage gnome-terminal tree libio-pty-perl libsys-virt-perl \
  libfile-homedir-perl curl w3m picocom expect lxc aptsh libxml-tidy-perl inkscape \
  linux-image-extra-virtual wmctrl wireshark x11-apps

# Add sentences to /etc/profile to set DISPLAY variable to host ip address
# (needed for windows machines). And to set XAUTHORITY variable (needed to have 
# X windows working afeter a sudo su)
cat >> /etc/profile <<EOF
if [ -z \$DISPLAY ]; then
 export DISPLAY="\$(ip route show default | head -1 | awk '{print \$3}'):0"
 #echo "Setting DISPLAY to \$DISPLAY"
export XAUTHORITY=~/.Xauthority

echo ""
echo "---- Installing VNX application:"
echo ""

mkdir /tmp/vnx-update
cd /tmp/vnx-update
rm -rf /tmp/vnx-update/vnx-*
tar xfvz vnx-latest.tgz
cd vnx-*
sudo ./install_vnx

sudo mv /usr/share/vnx/etc/vnx.conf.sample /etc/vnx.conf
# Set svg viewer to inkview
sed -i -e '/\[general\]/{:a;n;/^$/!ba;i\svg_viewer=inkview' -e '}' /etc/vnx.conf
# Set console to xterm
sed -i -e '/console_term/d' /etc/vnx.conf
sed -i -e '/\[general\]/{:a;n;/^$/!ba;i\console_term=xterm' -e '}' /etc/vnx.conf

echo ""
echo "---- Installing VNX LXC rootfs:"
echo ""

cd /usr/share/vnx/filesystems/
/usr/bin/vnx_download_rootfs -l -r vnx_rootfs_lxc_ubuntu-14.04-v025 -y
ln -s rootfs_lxc_ubuntu rootfs_lxc

echo "-- Rebooting to finish installation..."

echo "----"

Personal tools