2016-11-07

How to customize an OpenStack Cloud image

Scenario: You have an image in your OpenStack Cloud tenant, but you need to customize it.

Solution: Shut down the image, shapshot it, create a new image from the snapshot. If necessary, download the new image.

Detailed instructions, mostly lifted from this OpenStack documentation page:


  1. List instances:

    $ nova list
    +--------------------------------------+------------+--------+------------------------------+
    | ID                                   | Name       | Status | Networks                     |
    +--------------------------------------+------------+--------+------------------------------+
    | c41f3074-c82a-4837-8673-fa7e9fea7e11 | myInstance | ACTIVE | private=10.0.0.3             |
    +--------------------------------------+------------+--------+------------------------------+
    

  2. Use the nova stop command to shut down the instance:

    $ nova stop myInstance
    

  3. Use the nova list command to confirm that the instance shows a SHUTOFF status:

    $ nova list
    +--------------------------------------+------------+---------+------------------+
    | ID                                   | Name       | Status  | Networks         |
    +--------------------------------------+------------+---------+------------------+
    | c41f3074-c82a-4837-8673-fa7e9fea7e11 | myInstance | SHUTOFF | private=10.0.0.3 |
    +--------------------------------------+------------+---------+------------------+
    

  4. Use the nova image-create command to take a snapshot:

    $ nova image-create --poll myInstance myInstanceSnapshot
    Instance snapshotting... 100% complete
    

  5. Use the openstack image list command to check the status until the status is active:

    $ openstack image list
    +--------------------------------------+---------------------------------+--------+
    | ID                                   | Name                            | Status |
    +--------------------------------------+---------------------------------+--------+
    | 657ebb01-6fae-47dc-986a-e49c4dd8c433 | cirros-0.3.2-x86_64-uec         | active |
    | 72074c6d-bf52-4a56-a61c-02a17bf3819b | cirros-0.3.2-x86_64-uec-kernel  | active |
    | 3c5e5f06-637b-413e-90f6-ca7ed015ec9e | cirros-0.3.2-x86_64-uec-ramdisk | active |
    | f30b204e-1ce6-40e7-b8d9-b353d4d84e7d | myInstanceSnapshot              | active |
    +--------------------------------------+---------------------------------+--------+
    

  6. Get the image ID:

    $ openstack image list
    +-------------------+-------------------+--------+
    | ID                | Name              | Status |
    +-------------------+-------------------+--------+
    | f30b204e-1ce6...  | myInstanceSnapshot| active |
    +-------------------+-------------------+--------+
    

  7. Download the snapshot by using the image ID that was returned in the previous step (N.B.: the glance image-download command requires the image ID and cannot use the image name):

    $ glance image-download --file myNewImage.img f30b204e-1ce6-40e7-b8d9-b353d4d84e7d
    

  8. Determine format of image file:

    $ qemu-img info myNewImage.img
    

  9. Upload the image (e.g. to a different tenant/region):

    $ glance image-create --name='myNiceNewImage' --container-format=bare --disk-format=qcow2 < myNewImage.img
    
  10. Delete the snapshot:

    openstack image delete myInstanceSnapshot
    

No comments:

Post a Comment