Managing Virtual Machine Images 2.2

The Image Repository system allows OpenNebula administrators and users to set up images, which can be operative systems or data, to be used in Virtual Machines easily. These images can be used by several Virtual Machines simultaneously, and also shared with other users.

If you want to customize the Image Repository in your system, visit the configuration guide.

What Is an Image

An OpenNebula image is a resource containing an operative system or data, to be used as a virtual machine disk. This data can be then saved overwriting the original image, or as a new OpenNebula image.

Administrators and users can upload images to use them in their own Virtual Machines, or to be shared with all the users.

Image Types

There are three different types of images.

  • OS: An OS image contains a working operative system. Every VM template must define one DISK referring to an image of this type.
  • CDROM: This images are readonly data. Only one image of this type can be used in each VM template.
  • DATABLOCK: A datablock image is a storage for data, which can be accessed and modified from different Virtual Machines. This images can be created from previous existing data, or as an empty drive.

The Virtual Machines can use as many datablocks as needed. Refer to the VM template documentation for further information.

Image Life Cycle

The images can be in any of the following states:

  • INIT: Initialization state.
  • READY: Image ready to use.
  • USED: The Image is in use by one or more virtual machines.
  • DISABLED: Filesystem operation on the image in progress. The image can not be used by a VM in this state.

Managing Images

Users can manage the image repository using the command line interface command oneimage. The complete reference is here.

Create an OS Image

If you want to create an OS image, you need to prepare a contextualized virtual machine, and extract its disk.

Please read first the documentation about the MAC to IP mechanism in the virtual network management documentation, and how to use contextualization here.

Once you have a disk you want to upload, you need to create a new image template, and submit it using the oneimage register command.

The complete reference for the image template is here. This is how a sample template looks like:

<xterm> $ cat ubuntu.one.img NAME = “Ubuntu Desktop” PATH = /home/cloud/images/ubuntu-desktop/disk.0 PUBLIC = YES DESCRIPTION = “Ubuntu 10.04 desktop for students.” </xterm>

To submit the template, you just have to issue the command <xterm> $ oneimage register ubuntu_img.one </xterm>

Listing Available Images

You can use the oneimage list command to check the available images in the repository.

<xterm> $ oneimage list

ID     USER                 NAME TYPE              REGTIME PUB PER STAT  #VMS
 1   carlos       Ubuntu Desktop   OS   Jul 11, 2010 15:17 Yes  No  rdy     0

</xterm>

To get complete information about an image, use oneimage show, or list images continuously with oneimage top.

Adding and Deleting Images

Using oneimage register, users can create new images for private or public use. The oneimage delete command allows the image owner -or the OpenNebula administrator- to delete it from the repository.

Another way to create a new image is copying it from an existing one. To do this, the user has to mount the original image in a virtual machine template, and then use the onevm saveas command. OpenNebula will save the changes made to the source image as a new one when the machine is shut down.

Publishing Images

Use the oneimage publish and oneimage unpublish commands to make your images public for every user to use in their virtual machines, or private.

<xterm> $ oneimage list

ID     USER                 NAME TYPE              REGTIME PUB PER STAT  #VMS
 1   carlos       Ubuntu Desktop   OS   Jul 11, 2010 15:17 Yes  No  rdy     0

$ oneimage unpublish “Ubuntu Desktop” $ oneimage list

ID     USER                 NAME TYPE              REGTIME PUB PER STAT  #VMS
 1   carlos       Ubuntu Desktop   OS   Jul 11, 2010 15:17  No  No  rdy     0

$ oneimage publish 1 $ oneimage list

ID     USER                 NAME TYPE              REGTIME PUB PER STAT  #VMS
 1   carlos       Ubuntu Desktop   OS   Jul 11, 2010 15:17 Yes  No  rdy     0

</xterm>

Making Images Persistent

Use the oneimage persistent and oneimage nonpersistent commands to make your images persistent (they are not cloned, but rather used from the original image) or not.

<xterm> $ oneimage list

ID     USER                 NAME TYPE              REGTIME PUB PER STAT  #VMS
 1   carlos       Ubuntu Desktop   OS   Jul 11, 2010 15:17  No  No  rdy     0

$ oneimage persistent “Ubuntu Desktop” $ oneimage list

ID     USER                 NAME TYPE              REGTIME PUB PER STAT  #VMS
 1   carlos       Ubuntu Desktop   OS   Jul 11, 2010 15:17  No Yes  rdy     0

$ oneimage nonpersistent 1 $ oneimage list

ID     USER                 NAME TYPE              REGTIME PUB PER STAT  #VMS
 1   carlos       Ubuntu Desktop   OS   Jul 11, 2010 15:17  No  No  rdy     0

</xterm>

:!: When images are published they are always cloned, and persistent images are never cloned. Therefore, an image cannot be public and persistent at the same time. To manage a public image that won't be cloned, unpublish it first and make it persistent.

How to Use Images in Virtual Machines

This a simple example on how to specify images as virtual machine disks. Please visit the virtual machine user guide and the virtual machine template documentation for a more thorough explanation.

Assuming you have an OS image called “Ubuntu desktop”, you can use it in your virtual machine template as a DISK. When this machine is deployed, the first disk will be taken from the image repository.

CPU    = 1
MEMORY = 2048

DISK = [ image     = "Ubuntu Desktop" ]

DISK = [ type   = swap,
         size   = 1024  ]

NIC    = [ NETWORK = "Public network" ]
NIC    = [ NETWORK = "Private network" ]

# FEATURES=[ acpi="no" ]

GRAPHICS = [ 
  type    = "vnc",              
  listen  = "1.2.3.4",
  port    = "5902"  ]


CONTEXT = [
    files      = "/home/cloud/images/ubuntu-desktop/init.sh"  ]

Save Changes

Once the VM is deployed you can save the changes made to any disk as a new image. To do so, use the onevm saveas command. This command takes three or four arguments: The VM name (or ID), the disk_id to save, the name of the new image to register, and optionally the image type.

To know the DISK_ID of the disk you want to save, just take a look at the onevm show output for your VM.

<xterm> $ onevm show 5 VIRTUAL MACHINE 5 INFORMATION ID : 5 NAME : one-5 STATE : ACTIVE LCM_STATE : RUNNING START TIME : 07/27 14:43:58 END TIME : - DEPLOY ID: : one-5

VIRTUAL MACHINE TEMPLATE CONTEXT=[

FILES=/home/cloud/images/ubuntu-desktop/init.sh,
TARGET=hdb ]

CPU=1 DISK=[

CLONE=YES,
DISK_ID=0,
IMAGE=Ubuntu Desktop,
IMAGE_ID=10,
READONLY=NO,
SAVE=NO,
SOURCE=/home/cloud/opennebula/var/images/147f94ddb708851e71651f05caf81da0131cc904,
TARGET=hda,
TYPE=DISK ]

DISK=[

DISK_ID=1,
SIZE=1024,
TARGET=hdd,
TYPE=swap ]

GRAPHICS=[

LISTEN=1.2.3.4,
PORT=5902,
TYPE=vnc ]

MEMORY=2048 NAME=one-5 NIC=[

BRIDGE=bpub,
IP=1.2.3.4,
MAC=02:00:01:02:03:04,
NETWORK=Public network,
NETWORK_ID=1 ]

NIC=[

BRIDGE=bpriv,
IP=192.168.30.1,
MAC=02:00:c0:a8:1e:01,
NETWORK=Private network,   
NETWORK_ID=0 ]

VMID=5 </xterm>

The DISK_IDs are assigned in the same order the disks were defined in the VM template.

<xterm> $ onevm saveas one-5 0 “Ubuntu with Apache and MySQL” </xterm>

This will register a new image called “Ubuntu with Apache and MySQL”, that will be ready as soon as the VM is shut down.

The disks can be saved even if they were defined from a local disk file (see the VM template reference guide for more information on the different kinds of disks).

Using Sunstone to Manage Images

You can also manage your images using the OpenNebula Cloud Operations Center. Select the Images tab, and there, you will be able to create, enable, disable, delete your images and even manage their persistence and publicity in a user friendly way.