Atom feed of this document
 

 Creating images from running instances with KVM and Xen

It is possible to create an image from a running instance on KVM and Xen. This is a convenient way to spawn pre-configured instances; update them according to your needs ; and re-image the instances. The process to create an image from a running instance is quite simple :

  • Pre-requisites (KVM)

    In order to use the feature properly, you will need qemu-img 0.14 or greater. The imaging feature uses the copy from a snapshot for image files. (e.g qcow-img convert -f qcow2 -O qcow2 -s $snapshot_name $instance-disk).

    On Debian-like distros, you can check the version by running :

    dpkg -l | grep qemu
    ii  qemu                            0.14.0~rc1+noroms-0ubuntu4~ppalucid1            dummy transitional pacakge from qemu to qemu
    ii  qemu-common                     0.14.0~rc1+noroms-0ubuntu4~ppalucid1            qemu common functionality (bios, documentati
    ii  qemu-kvm                        0.14.0~rc1+noroms-0ubuntu4~ppalucid1            Full virtualization on i386 and amd64 hardwa
                       

    Images can only be created from running instances if Compute is configured to use qcow2 images, which is the default setting. You can explicitly enable the use of qcow2 images by adding the following line to nova.conf:

    use_cow_images=true
                       

  • Write data to disk

    Before creating the image, we need to make sure we are not missing any buffered content that wouldn't have been written to the instance's disk. In order to resolve that ; connect to the instance and run sync then exit.

  • Create the image

    In order to create the image, we first need obtain the server id :

    nova list
    +-----+------------+--------+--------------------+
    |  ID |    Name    | Status |      Networks      |
    +-----+------------+--------+--------------------+
    | 116 | Server 116 | ACTIVE | private=20.10.0.14 |
    +-----+------------+--------+--------------------+
                           

    Based on the output, we run :

    nova image-create 116 Image-116

    The command will then perform the image creation (by creating qemu snapshot) and will automatically upload the image to your repository.

    [Note]Note

    The image that will be created will be flagged as "Private" (For glance : is_public=False). Thus, the image will be available only for the tenant.

  • Check image status

    After a while the image will turn from a "SAVING" state to an "ACTIVE" one.

    nova image-list

    will allow you to check the progress :

    nova image-list 

    +----+---------------------------------------------+--------+
    | ID |                     Name                    | Status |
    +----+---------------------------------------------+--------+
    | 20 | Image-116                                   | ACTIVE |
    | 6  | ttylinux-uec-amd64-12.1_2.6.35-22_1-vmlinuz | ACTIVE |
    | 7  | ttylinux-uec-amd64-12.1_2.6.35-22_1-initrd  | ACTIVE |
    | 8  | ttylinux-uec-amd64-12.1_2.6.35-22_1.img     | ACTIVE |
    +----+---------------------------------------------+--------+
                           

  • Create an instance from the image

    You can now create an instance based on this image as you normally do for other images :

    nova boot --flavor 1 --image 20 New_server

  • Troubleshooting

    Mainly, it wouldn't take more than 5 minutes in order to go from a "SAVING" to the "ACTIVE" state. If this takes longer than five minutes, here are several hints:

    - The feature doesn't work while you have attached a volume (via nova-volume) to the instance. Thus, you should dettach the volume first, create the image, and re-mount the volume.

    - Make sure the version of qemu you are using is not older than the 0.14 version. That would create "unknown option -s" into nova-compute.log.

    - Look into nova-api.log and nova-compute.log for extra information.



loading table of contents...