Deploy a virtualized environment -- other alternatives

From Grid5000

Jump to: navigation, search


Coupling Xen, LVM and Snapshotting methods

The problem with the method explained in Deploy a virtualized environment is that each virtual machines (vm) created will lead in duplicating the base image file. This file is about 400MB and thus the host's local disk may be unnecessarily solicited. Thus the LVM + snapshotting system may be interesting. With this method, instead of duplicating the same file N times for the N virtual machines, Xen will use the same base image and then for each vm create a "snapshot" of only a few MB.


  • Connect the Nancy site frontend:
Image:Terminal.png workstation:
# ssh nancy.g5k

Reserve a node for deployment

Image:Terminal.png frontend@nancy:
# oarsub -l nodes=1,walltime=2 -t deploy -I

Deploy the xen environment

Image:Terminal.png frontend@nancy:
# kadeploy3 -e squeeze-x64-xen-TP -u jemeras -f $OAR_NODE_FILE -d -k
  • Then connect to the Xen host machine (<NODE> is the name of the node you reserved, to get it type cat $OAR_NODE_FILE | uniq):
Image:Terminal.png frontend@nancy:
# ssh root@<NODE>
  • Add a virtual machine automatically by running the xen-lvm-add-domu script:
Image:Terminal.png dom0:
# xen-lvm-add-domu

This will start a new vm based on the original domU image. Each time you call this script a new vm is thus created. Since we use LVM+snapshoting the total size used regardless of how many virtual machines we created will be less than 1GB. Try adding more than one vm, you'll see that Xen is able to run a lot of vms with this method...

List the vms with:

Image:Terminal.png dom0:
# xm list

Connect to a vm (login: root -- password: grid5000):

Image:Terminal.png dom0:
# xm console vm0
Image:Note.png Note

Take a look at this script. It will use the partition mounted on /tmp (/dev/sda5 on every grid5000 sites) to store a copy of the initial xen domU image and all the vm snapshots (this is done by the init_tmp_partition, init_lvm2 and create_root_lv functions in the script). The first time this script is called, an LVM volume will be created on the sda5 partition, create a snapshot from the original domU image and then start the associated vm (this part is managed by the add_vm function). Then, for the other calls, only the snapshot part will be executed.


Exit the vm with:

Image:Terminal.png dom0:
# ctrl+]


Modifying the domU image without connecting the virtual machine

You may want to do some changes on the domU image without connecting the machine. This is possible by mounting the image.

Image:Terminal.png dom0:
# mkdir /mnt/domU
Image:Terminal.png dom0:
# mount -o loop /dev/g5k/<vm_number>-disk /mnt/domU

Now, you'll be able to access the vm file system, mounted on /mnt/domU.

Then, once the changes are done, just unmount the vm image file

Image:Terminal.png dom0:
# umount /mnt/domU

Using KVM instead of Xen

An other alternative to Xen is KVM. This virtualization tool is also very efficient but needs a little bit more work to do to be used on G5k. As Xen was able to connect the virtual machines directly through the "xm console" command, KVM doesn't offer such tool. When the vm boots for the first time it is not possible to know in advance its IP address. Thus we have to connect it by another method. An "easy" way to do this is through VNC. We will have to manage the network bridging ourselves too, but don't worry :-) some scripts are here to help you in this procedure.


  • On Nancy site frontend, deploy the squeeze-x64-kvm-TP environment (don't forget to submit a job first...):
Image:Terminal.png frontend@nancy:
# kadeploy3 -e squeeze-x64-kvm-TP -u jemeras -f $OAR_NODE_FILE -d -k
  • On the deployed node:

Get network interface for bridge creation (INTERFACE=`ifconfig | grep eth | awk -F ' ' '{print $1}'`)

Create bridge for managing hosts network (replace <$INTERFACE> by what you got typing ifconfig | grep eth | awk -F ' ' '{print $1}')

Image:Terminal.png node:
# create_bridge.sh <$INTERFACE>


Restart networking

Image:Terminal.png node:
# /etc/init.d/networking restart

Verify that the bridge was actually created:

Image:Terminal.png node:
# brctl show

should display the bridge information


Image:Terminal.png node:
# ifconfig

Now, a new interface br0 should appear in ifconfig

Generate a random mac address for use in the vm

Image:Terminal.png node:
# random_mac.sh

Start the Virtual Machine

Image:Terminal.png node:
# kvm -m 512 -hda /root/kvm/debian.qcow2 -net nic,macaddr=00:16:3E:6D:FB:4C -net tap -nographic -vnc :1
Image:Note.png Note

Don't forget to replace the macaddr field by the one you got by running the command "random_mac.sh" otherwise we will all use the same IP address and it will not work!!!

  • On your laptop/desktop machine:

Create an ssh tunnel to your deployed node (<NODE>)

Image:Terminal.png laptop:
# ssh -L 5901:<NODE>:5901 grenoble.g5k

Then, to open the vnc console through the tunnel

Image:Terminal.png laptop:
# vncviewer localhost:5901

You should have a window that opened. This is your virtual machine (login:root -- password: kameleon).

Now, you can be able to know its IP address (with "ifconfig") and then connect it directly through ssh from within Grid'5000.

Personal tools
Wiki special pages