Difference between revisions of "Vnx-create-vagrant-vm"

From VNX
Jump to: navigation, search
(bootstrap.sh file content)
Line 95: Line 95:
 
# (www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es)  
 
# (www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es)  
 
#  
 
#  
# Departamento de Ingeniería de Sistemas Telemáticos (DIT)
+
# Departamento de Ingenieria de Sistemas Telematicos (DIT)
# Universidad Politécnica de Madrid
+
# Universidad Politecnica de Madrid
 
# SPAIN
 
# SPAIN
 
#
 
#
 +
  
 
HOSTNAME=vnx
 
HOSTNAME=vnx
Line 110: Line 111:
 
echo $HOSTNAME > /etc/hostname
 
echo $HOSTNAME > /etc/hostname
 
hostname $HOSTNAME
 
hostname $HOSTNAME
sed -i -e "s/127.0.1.1.*/127.0.1.1  $HOSTNAME/" /etc/hosts
+
sed -i -e '/^127.0.1.1/d' /etc/hosts
 +
sed -i -e '/^127.0.0.1/{:a;n;/^$/!ba;i\127.0.1.1\t$HOSTNAME' -e '}' /etc/hosts
 +
#sed -i -e "s/127.0.1.1.*/127.0.1.1  $HOSTNAME/" /etc/hosts
  
 
echo ""
 
echo ""
Line 117: Line 120:
  
 
apt-get update
 
apt-get update
 +
apt-get -y dist-upgrade
 
apt-get -y install qemu-kvm libvirt-bin vlan xterm bridge-utils screen virt-manager \
 
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 \
 
   virt-viewer libxml-checker-perl libxml-parser-perl libnetaddr-ip-perl libnet-pcap-perl \
Line 124: Line 128:
 
   libdbi-perl graphviz genisoimage gnome-terminal tree libio-pty-perl libsys-virt-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 \
 
   libfile-homedir-perl curl w3m picocom expect lxc aptsh libxml-tidy-perl inkscape \
   linux-image-extra-virtual wmctrl
+
   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"
 +
fi
 +
export XAUTHORITY=~/.Xauthority
 +
EOF
  
 
echo ""
 
echo ""

Revision as of 00:50, 2 September 2014

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:

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 vnx-ubuntu-14.04-v01.box --vagrantfile Vagrantfile.pkg
    
  • Optionally, copy the file created (vnx-ubuntu-14.04-v01.box) 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 http://idefix.dit.upm.es/vnx/vagrant-vnx/vnx-ubuntu-14.04-v01.box
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"]
  end

Vagrantfile content

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

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

bootstrap.sh file content

#!/usr/bin/env bash

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


HOSTNAME=vnx

echo "-- Installing VNX:"

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

echo $HOSTNAME > /etc/hostname
hostname $HOSTNAME
sed -i -e '/^127.0.1.1/d' /etc/hosts
sed -i -e '/^127.0.0.1/{:a;n;/^$/!ba;i\127.0.1.1\t$HOSTNAME' -e '}' /etc/hosts
#sed -i -e "s/127.0.1.1.*/127.0.1.1   $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"
fi
export XAUTHORITY=~/.Xauthority
EOF

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

mkdir /tmp/vnx-update
cd /tmp/vnx-update
rm -rf /tmp/vnx-update/vnx-*
wget http://vnx.dit.upm.es/vnx/vnx-latest.tgz
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..."
reboot

echo "----"