Create a VM Image in OpenNebula

Tested on OpenNebula 4.4.1 on CentOS 6.5. It should work on recent OpenNebula versions.

This is almost copied from Tutorial: Deploy VM Using Image Created On OpenNebula Directly, for preservation and my own personal use. Check the original link first.

Step 1. Uploading the Installation CD Image

a. Go to Virtual Resources -> Images -> Create
b. Set Type to CDROM.
c. Leave Persistent unchecked.
d. Use either Provide a path and set it to a URL pointing to an OS installation image or Upload and set it to an already downloaded OS installation image.

We now have an installation cdrom image in our datastore

Step 2. Creating an empty hard disk (Datablock)

a. Goto Virtual Resources -> Images -> Create
b. Set Type to Datablock
c. Tick Persistent. Every change made to this datablock needs to persist since this is going to be the hard drive for each newly deployed VM.
d. e. Set Image Location to Empty datablock, set Size and (optionally) FS type and FS Driver to qcow2.
e. Set Driver prefix to sd.
f. Last time I wasn’t setting FS Driver to qcow2 and ONE would barf

This will create an empty datablock which will be used to install the OS.

Step 3. Creating an OS image installation template

a. Goto Virtual Resources -> Templates -> Create
b. We are going to use the installation CD (Step 1) and the Datablock (Step 2). So, in Storage attach the installation CD and set READONLY to yes and attach the datablock as well.
c. Set the Network (select a nic)
d. Under OS Booting: In Boot set Boot to CDROM and in Features set ACPI to yes.
e. Under Input/Output set VNC and Listen IP to
f. Under Context tick Add Network contextualisation and Add OnGate token.

Step 4. Deploy a VM based on the OS image installation template (Step 3)

a. Instantiate the template. This will create a VM, which will boot from the CDROM (Step 1) and install the OS in the datablock disk (Step2).
b. Shutdown the VM when installation is complete and delete the VM. Remember, our datablock is persistent so the OS is installed and all changes are persistent.
c. Goto Virtual Resources -> Images and change its Type from Datablock to OS.

Step 5. Create a VM preparation template.

a. Create a normal template. Under Storage attach only the disk we created on Step 4. The VM boots from this disk.
b. NB: don’t do this is you want to have noVNC working!! Under Other pass the following in the RAW data section and set the Type to KVM. in order to enable serial console access, from KVM side. This requires to enable it from the VM’s kernel side as well by tweaking the grub config file that specifies kernel options during boot.
<devices><serial type="pty"><source path="/dev/pts/5"/><target port="0"/></serial><console type="pty" tty="/dev/pts/5"><source path="/dev/pts/5"/><target port="0"/></console></devices>
c. All other settings just like Step 3.

Instantiate the template and start a VM.

Step 6. Contextualisation

In our newly created VM:

a. Go to Basic Contextualisation. The process is not straight forward so here’s a rough guide.
– Open VM’s VNC console.
– Setup the network for the VM.
– Setup ONE repository and install the contextualisation deb package. UPDATE: Download it manually at since I can’t find it in the ONE repo.
b. NB: don’t do this is you want to have noVNC working!! To enable serial console access from the VM side, open /etc/default/grub and set the following:
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
– Create /etc/init/ttyS0.conf with the following contents:
# ttyS0 - getty
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on stopped rc or RUNLEVEL=[12345]
stop on runlevel [!12345]
exec /sbin/getty -L -w 115200 ttyS0 vt102

– Full instructions at
b. Prepare the VM, i.e. clean and make it pristine, following this guide.
c. Shutdown the VM and delete it.

Finally go to the OS image and set its Type to non persistent.

We can now use the OS image to instantiate new VMs.

This entry was posted in OpenNebula. Bookmark the permalink.

Comments are closed.