Blog Article:

New Contextualization Packages for OpenNebula 3.8

Javier Fontan

Oct 18, 2012

Some weeks ago with the creation of the OpenNebula Marketplace, we released contextualization packages to help prepare VM images. These packages did some work that previously we had to do manually:

  • Disable/delete udev net and cdrom persistent rules. On boot, linux distributions scan for new hardware and discovered network and cdrom are added to a file. This process is really useful for physical machines so adding or taking out a new network card wont change the name of the rest, making the configuration we had still useful. With virtual machines this is a nuisance. A simple MAC address change will make udev create a new device for that interface and the configuration will no longer be used.
  • Unconfigure network. This way the VM won’t configure the network before the OpenNebula contextualization kicks in.
  • Add contextualization scripts to startup. These scripts will configure the network and will call from the context cdrom enabling us to do some magic with the context section of the VM template.

One of the changes introduced in OpenNebula 3.8 is the new contextualization packages. The new version does the same as the previous one with some changes that we hope will make people creating images happier.

Modular Contextualization Scripts

Now the script launched on VM boot has less logic:

  • Mounts the context cdrom
  • Exports the variables from
  • Executes any script located in /etc/one-context.d
  • Executes from cdrom
  • Unmounts the cdrom

Network configuration is now a script located in /etc/one-context.d/00-network. Any file located in that directory will be executed on start, in alphabetical order. This way we can add any script to configure or start processes on boot. For example, we can have a script that populates authorized_keys file using a variable in the Remember that those variables are exported to the environment and will be easily accessible by the scripts:

echo "$SSH_PUBLIC_KEY" > /root/.ssh/authorized_keys 


Network Configuration Driven by Contextualization

The new network configuration scripts can still infer the network configuration from the MAC address of the VM, the same as the previous versions. The way OpenNebula generates MAC addresses by default is by setting the first 2 bytes of the MAC address to the prefix configured in oned.conf and the rest 4 bytes to the IP assigned. This method is convenient but lacks flexibility and some interesting parameters like the network mask or gateway information.

Other way we had to configure the network was adding a script to the contextualization cdrom using the file. This method is very flexible but most of the time we always configure the same network parameters so this script changes very rarely. Also, in new OpenNebula versions we discourage the use of contextualization file parameter as it can lead to security problems.

Now the network configuration script will search for some predefined environment variables to configure network parameters. The parameters are:

Attribute Description
<DEV>_IP IP assigned to the interface
<DEV>_NETWORK Interface network
<DEV>_MASK Interface net mask
<DEV>_GATEWAY Interface gateway


We will substitute <DEV> with the interface the variable refers to in uppercase, as in ETH0, ETH1, etc. As an example, we can have a network defined this way:



And then in the VM contextualization those parameters for eth0 can be expressed as:

 ETH0_IP = "$NIC[IP, NETWORK=\"public\"]",


Generation of Custom Contextualization Packages

OpenNebula source code comes with the scripts and the files needed to generate those packages. This way you can also generate custom packages tweaking the scripts that will go inside your images or adding new scripts that will perform other duties.

The files are located in share/scripts/context-packages:

  • base: files that will be in all the packages. Right now it contains empty udev rules and the init script that will be executed on startup.
  • base_<type>: files specific for linux distributions. It contains the contextualization scripts for the network and comes in rpm and deb flavors. You can add here your own contextualization scripts and they will be added to the package when you run the generation script.
  • The script that generates the packages.
  • postinstall: This script will be executed after the package installation and will clean the network and udevconfiguration. It will also add the init script to the started services on boot.

To generate the packages you will need:

  • Ruby >= 1.8.7
  • gem fpm
  • dpkg utils for deb package creation
  • rpm utils for rpm package creation

You can also give to the generation script some parameters using env variables to generate the packages. For example, to generate an rpm package you will execute:

$ PACKAGE_TYPE=rpm ./ 


These are the default values of the parameters, but you can change any of them the same way we did forPACKAGE_TYPE:

This package prepares a VM image for OpenNebula:
 * Disables udev net and cd persistent rules
 * Deletes udev net and cd persistent rules
 * Unconfigures the network
 * Adds OpenNebula contextualization scripts to startup

To get support use the OpenNebula mailing list:"


For more information check the file from that directory.



  1. » Archives » OPENNEBULA NEWSLETTER – NOVEMBER 2012 - [...] of the changes introduced in OpenNebula 3.8 is the new contextualization packages The new version comes with some changes…
  2. OSPN Press 第29号 (2012/11/14発行) - [...] ◆2012/10/22 『オープンソースのクラウド構築ツールキット「OpenNebula 3.8」リリース』 → [...]
  3. » Archives » OpenNebula 2012: Year in Review - [...] a set of  contextualization packages have been developed to aid in the contextualization of guest images by OpenNebula, smoothing the…

Submit a Comment

Your email address will not be published. Required fields are marked *