Instance volume management¶
Upload volume of a running instance as a Glance image¶
This can be useful in case you need to migrate an instance from one OpenStack cluster to another.
Source your OpenStack environment file:
$ source openstack.rc
Find the INSTANCE_ID of the VM called $INSTANCE:
$ nova list | grep $INSTANCE
Find the ID of the volume attached to the VM:
$ nova show $INSTANCE_ID
Take note of the volume ID associated to the parameter os-extended-volumes:volumes_attached:
+--------------------------------------+--------------------------------------------------+ | Property | Value | +--------------------------------------+--------------------------------------------------+ | ... | ... | +--------------------------------------+--------------------------------------------------+ | os-extended-volumes:volumes_attached | [{"id": "71ac5a23-3643-49c8-ad1a-0f18c6eb7634"}] | +--------------------------------------+--------------------------------------------------+
Convert the volume to a Glance image:
$ cinder upload-to-image --disk-format qcow2 --force=True $VOLUME_ID $IMAGE_NAME
where $IMAGE_NAME is the name of the newly created Glance image. The –force flag is required as the volume is attached to the instance.
When the above process is done find the ID of the image:
$ glance image-list | grep $IMAGE_NAME
Download the image to a local file called $IMAGE_FILE_NAME:
$ glance image-download $IMAGE_ID --file $IMAGE_FILE_NAME
The image can now be uploaded to another OpenStack cluster to spawn VM clones of the original instance!
Upload volume of a running instance as a Glance image - Manual procedure¶
The automatic upload-to-image procedure described above consists of three steps (in this example the volume backend is Ceph):
The volume is exported (downloaded) on the local /tmp of the Cinder service;
The volume is converted to a file in qcow2 format;
The file is uploaded to Glance via an API call.
The procedure may fail in some cases, for instance (it happened to us) because the /tmp partition was smaller than the volume size!
We solved the issue executing the three steps (logged in /var/log/cinder/cinder-volume.log) manually:
Log in to the Cinder server;
Find the Ceph volume ID of the instance volume:
rbd --pool $CINDER_POOL --user $CINDER_USER ls| grep $VOLUME_IDwhere $CINDER_POOL and $CINDER_USER are the Ceph pool and user name associated to Cinder. The Ceph volume ID should have the form volume-$VOLUME_ID
Export the volume to the local disk:
rbd export --pool $CINDER_POOL --id $CINDER_USER $CINDER_VOL_ID /path/to/local/$CINDER_VOL_ID --conf /etc/ceph/ceph.conf
At this point the volume can be directly uploaded to OpenStack Glance as a raw format image:
openstack image create --file /path/to/local/$CINDER_VOL_ID --disk-format raw $IMAGE_NAME
Alternatively it can be converted to a qcow2 format file:
qemu-img convert -O qcow2 /path/to/local/$CINDER_VOL_ID /path/to/local/$QCOW2_FILE_NAME
and then uploaded to OpenStack Glance as a qcow2 format image:
openstack image create --file /path/to/local/$QCOW2_FILE_NAME --disk-format qcow2 $IMAGE_NAME
Miscellanea¶
To directly spawn the VM from the volume in qcow2 format on a Linux terminal
Fedora platform:
qemu-kvm -hda /path/to/local/$QCOW2_FILE_NAME -m 1024
Debian platform:
kvm -hda /path/to/local/$QCOW2_FILE_NAME -m 1024
To check information on the image file:
$ qemu-img info /path/to/local/$QCOW2_FILE_NAME
The output will be something like:
image: /path/to/local/$QCOW2_FILE_NAME file format: raw virtual size: 80G (85899345920 bytes) disk size: 54G