Managing Volumes with the Command-line Interface

A volume is a detachable block storage device, similar to a USB hard drive. You can attach a volume to only one instance. To create and manage volumes, you use a combination of nova and cinder client commands.

To create a volume based on an image:

  1. List available images and note the ID of the image to use for your volume.

    $ openstack image list
    | ID                                   | Name                                  | Status |
    |--------------------------------------|---------------------------------------|--------|
    | c7d7bae6-4b01-4da0-a067-2bb8a791d9ac | Windows10-3                           | active |
    | 68db6198-89e7-4567-a3a3-229467b77cda | ubuntu_1204_server_cloudimg_amd64     | active |
    | a4a38ada-8a11-4259-9b4f-3606634f6e92 | test-my-first-snapshot                | active |
    | db0ff7c8-d6af-42da-b841-99eb9c300368 | Ubuntu-Server-16.04-CloudImage-raw    | active |
    
    
  2. List availability zones and note the ID of the AZ to create your volume.

    $ openstack availability zone list
    | Zone Name | Zone Status |
    |-----------|-------------|
    | internal  | available   |
    | trial9    | available   |
    
  3. Create a volume with 8 gibibytes (GiB) of space; specify the availability zone and image.

    $ cinder create 8 --display-name my-new-volume \
    --image-id 397e713c-b95b-4186-ad46-6126863ea0a9 \
    --availability-zone nova
    | Property            | Value                                |
    |---------------------|--------------------------------------|
    | attachments         | []                                   |
    | availability_zone   | nova                                 |
    | bootable            | false                                |
    | created_at          | 2013-07-25T17:02:12.472269           |
    | display_description | None                                 |
    | display_name        | my-new-volume                        |
    | id                  | 573e024d-5235-49ce-8332-be1576d323f8 |
    | image_id            | 397e713c-b95b-4186-ad46-6126863ea0a9 |
    | metadata            | {}                                   |
    | size                | 8                                    |
    | snapshot_id         | None                                 |
    | source_volid        | None                                 |
    | status              | creating                             |
    | volume_type         | None                                 |
    
  4. Verify that your volume was created successfully.

    $ openstack volume list
    | ID                                   | Display Name    | Status    | Size | Attached to |
    |--------------------------------------|-----------------|-----------|------|-------------|
    | 2c52eb67-8974-4f0a-a881-305ae3bb778f | my-new-volume   | available | 8    |             |
    | 03591e61-bbde-49be-ba3d-30b1b8285f8a | my-bootable-vol | available | 8    |             |
    

    If your volume was created successfully, its status is available. If its status is error, you may have exceeded your quota.

Creating a Volume from a Specified Volume Type

Pass one of the following parameters during volume creation:

  • volume_type
  • cinder_img_volume_type (through the Image service’s image metadata)

Note
If the parameters from the are not set, the Block Storage service uses default_volume_type, which is defined in Metacloud based on your storage configuration: nfs, ceph, or pure.

To create a volume using volume_type:

Add the --volume type paramenter when creating a volume.

$ openstack volume create --name <volume name> --volume-type <volume type> <size>

To create a volume using cinder_img_volume_type:

If the glance image has cinder_img_volume_type property, the Block Storage service uses this parameter to specify volume type when creating a volume.

  1. List images and note the ID of the image to use.

    $ openstack image list
    | ID                                   | Name                               | Status |
    |--------------------------------------|------------------------------------|--------|
    | c7d7bae6-4b01-4da0-a067-2bb8a791d9ac | Windows10-3                        | active |
    | 68db6198-89e7-4567-a3a3-229467b77cda | ubuntu_1204_server_cloudimg_amd64  | active |
    | a4a38ada-8a11-4259-9b4f-3606634f6e92 | test-my-first-snapshot             | active |
    | db0ff7c8-d6af-42da-b841-99eb9c300368 | Ubuntu-Server-16.04-CloudImage-raw | active |
    
  2. Choose the image that has cinder_img_volume_type property and create a volume from the image.

    $ openstack image show 6270942c-d6b9-47c3-ba60-fd538aa5cf9d 
    | Property         | Value                                |
    |------------------|--------------------------------------|
    | base_image_ref   | d8d7d917-1e79-4a90-b137-1e6a70dfaf0e |
    | checksum         | ddb7208d130957eba5bcb33d7185e0e2     |
    | container_format | bare                                 |
    | created_at       | 2016-07-27T06:47:55Z                 |
    | description      | LAMP Stack                           |
    | disk_format      | qcow2                                |
    | id               | 6270942c-d6b9-47c3-ba60-fd538aa5cf9d |
    | image_location   | snapshot                             |
    | image_state      | available                            |
    | image_type       | snapshot                             |
    | instance_uuid    | 34107dac-81a4-4b96-a062-ee1280d4ade7 |
    | kernel_id        | None                                 |
    | min_disk         | 20                                   |
    | min_ram          | 0                                    |
    | name             | Sample Snapshot                      |
    | owner            | 00a72b81702147289bfe3a5bf0848772     |
    | owner_id         | 00a72b81702147289bfe3a5bf0848772     |
    | protected        | False                                |
    | ramdisk_id       | None                                 |
    | size             | 1037697024                           |
    | status           | active                               |
    | tags             | []                                   |
    | updated_at       | 2016-07-27T06:48:04Z                 |
    | user_id          | c43c550c178b4e63831823a87273f9a4     |
    | virtual_size     | 21474836480                          |
    | visibility       | private                              |
    
  3. Create the volume including the --image <IMAGE_ID>, --size <#>, and ` –availability zone ` parameters.

    $ openstack volume create  --image 6270942c-d6b9-47c3-ba60-fd538aa5cf9d --size 1 --availablilty zone nova
    | Property                              | Value                                |
    |---------------------------------------|--------------------------------------|
    | attachments                           | []                                   |
    | availability_zone                     | nova                                 |
    | bootable                              | false                                |
    | consistencygroup_id                   | None                                 |
    | created_at                            | 2016-02-22T23:17:51.000000           |
    | description                           | None                                 |
    | encrypted                             | False                                |
    | id                                    | 123ad92f-8f4c-4639-ab10-3742a1d9b47c |
    | metadata                              | {}                                   |
    | migration_status                      | None                                 |
    | multiattach                           | False                                |
    | name                                  | test                                 |
    | os-vol-host-attr:host                 | None                                 |
    | os-vol-mig-status-attr:migstat        | None                                 |
    | os-vol-mig-status-attr:name_id        | None                                 |
    | os-vol-tenant-attr:tenant_id          | 4c0dbc92040c41b1bdb3827653682952     |
    | os-volume-replication:driver_data     | None                                 |
    | os-volume-replication:extended_status | None                                 |
    | replication_status                    | disabled                             |
    | size                                  | 1                                    |
    | snapshot_id                           | None                                 |
    | source_volid                          | None                                 |
    | status                                | creating                             |
    | updated_at                            | None                                 |
    | user_id                               | 9a125f3d111e47e6a25f573853b32fd9     |
    | volume_type                           | lvmdriver-1                          |
    

To attach a volume to an instance:

  1. Attach your volume to a server, specify the server ID and the volume ID.

    $ nova volume-attach 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 \573e024d-5235-49ce-8332-be1576d323f8 /dev/vdb
    | Property | Value                                |
    |----------|--------------------------------------|
    | device   | /dev/vdb                             |
    | serverId | 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 |
    | id       | 573e024d-5235-49ce-8332-be1576d323f8 |
    | volumeId | 573e024d-5235-49ce-8332-be1576d323f8 |
    

    Note the ID of your volume.

  2. Show information for your volume.

    $ cinder show 573e024d-5235-49ce-8332-be1576d323f8
    

    The output shows that the volume is attached to the server with ID 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5, is in the nova availability zone, and is bootable.

    | Property                     | Value                                      |
    |------------------------------|--------------------------------------------|
    | attachments                  | [{u'device': u'/dev/vdb',                  |
    |                              | u'server_id': u'84c6e57d-a                 |
    |                              | u'id': u'573e024d-...                      |
    |                              | u'volume_id': u'573e024d...                |
    | availability_zone            | nova                                       |
    | bootable                     | true                                       |
    | created_at                   | 2013-07-25T17:02:12.000000                 |
    | display_description          | None                                       |
    | display_name                 | my-new-volume                              |
    | id                           | 573e024d-5235-49ce-8332-be1576d323f8       |
    | metadata                     | {}                                         |
    | os-vol-host-attr:host        | devstack                                   |
    | os-vol-tenant-attr:tenant_id | 66265572db174a7aa66eba661f58eb9e           |
    | size                         | 8                                          |
    | snapshot_id                  | None                                       |
    | source_volid                 | None                                       |
    | status                       | in-use                                     |
    | volume_image_metadata        | {u'kernel_id': u'df430cc2...,              |
    |                              | u'image_id': u'397e713c...,                |
    |                              | u'ramdisk_id': u'3cf852bd...,              |
    |                              | u'image_name': u'cirros-0.3.2-x86_64-uec'} |
    | volume_type                  | None                                       |
    

To resize a volume:

  1. Detach the volume from your server, pass the server ID and volume ID to the following command.

    $ nova volume-detach 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5   573e024d-5235-49ce-8332-be1576d323f8
    

    The volume-detach command does not return any output.

  2. List available volumes.

    $ openstack image list
    | ID                                   | Name                              | Status |
    |--------------------------------------|-----------------------------------|--------|
    | 573e024d-5235-49ce-8332-be1576d323f8 | my-new-volume                     | active |
    | 68db6198-89e7-4567-a3a3-229467b77cda | ubuntu_1204_server_cloudimg_amd64 | active |
    
    

    Note that the volume is now available.

  3. Resize the volume by passing the volume ID and the new size (a value greater than the old one) as parameters.

    $ cinder extend 573e024d-5235-49ce-8332-be1576d323f8 10
    

    The extend command does not return any output.

To delete a volume:

  1. Detach the volume from your server, pass the server ID and volume ID to the following command.
$ nova volume-detach 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5   573e024d-5235-49ce-8332-be1576d323f8

The volume-detach command does not return any output.

  1. Delete the volume using either the volume name or ID.

    $ cinder delete my-new-volume
    

    The delete command does not return any output.

  2. List the volumes again, and note that the status of your volume is deleting.

    $ openstack image list
    | ID                                   | Name                              | Status   |
    |--------------------------------------|-----------------------------------|----------|
    | 573e024d-5235-49ce-8332-be1576d323f8 | my-new-volume                     | deleting |
    | 68db6198-89e7-4567-a3a3-229467b77cda | ubuntu_1204_server_cloudimg_amd64 | active   |
    | a4a38ada-8a11-4259-9b4f-3606634f6e92 | test-my-first-snapshot            | active   |   
    

    When the volume is deleted, it does not display in the list of volumes.

    $ openstack image list
    | ID                                   | Name                                  | Status |
    |--------------------------------------|---------------------------------------|--------|
    | 68db6198-89e7-4567-a3a3-229467b77cda | ubuntu_1204_server_cloudimg_amd64     | active |
    | a4a38ada-8a11-4259-9b4f-3606634f6e92 | test-my-first-snapshot                | active |
    | db0ff7c8-d6af-42da-b841-99eb9c300368 | Ubuntu-Server-16.04-CloudImage-raw    | active |
    

Transfering a Volume

You can transfer a volume from one owner to another by using the cinder transfer* commands. The volume donor, or original owner, creates a transfer request and sends the created transfer ID and authorization key to the volume recipient. The volume recipient, or new owner, accepts the transfer by using the ID and key.

Note
The procedure for volume transfer is intended for tenants (both the volume donor and recipient) within the same cloud.

You can transfer a volume to perform the following:

  • Create a custom bootable volume or a volume with a large data set and transfer it to a customer.

  • Complete bulk import of data to the cloud, the data ingress system creates a new Block Storage volume, copies data from the physical device, and transfers device ownership to the end user.

To create a volume transfer request:

To create a volume transfer request:

  1. List the available volumes.

    $ openstack image list
    | ID                                   | Name                              | Status |
    |--------------------------------------|-----------------------------------|--------|
    | 573e024d-5235-49ce-8332-be1576d323f8 | my-new-volume                     | active |
    | 68db6198-89e7-4567-a3a3-229467b77cda | ubuntu_1204_server_cloudimg_amd64 | active |
    | a4a38ada-8a11-4259-9b4f-3606634f6e92 | test-my-first-snapshot            | active |
    
  2. Request a volume transfer authorization code for a specific volume.

    $ cinder transfer-create volumeID
    

    The volume must be in an available state or the request will be denied. If the transfer request is valid in the database (that is, it has not expired or been deleted), the volume is placed in an awaiting transfer state. For example:

    $ cinder transfer-create a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f
    

    The output shows the volume transfer ID in the id row and the authorization key.

  3. Specify a name for the transfer by using the --display-name displayName parameter.

    |  Property  |                Value                 |
    |------------|--------------------------------------|
    |  auth_key  |           b2c8e585cbc68a80           |
    | created_at |      2013-10-14T15:20:10.121458      |
    |     id     | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc |
    |    name    |                 None                 |
    | volume_id  | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f |
    

    Note
    While the auth_key property is visible in the output of cinder transfer-create VOLUME_ID, it will not be available in subsequent cinder transfer-show TRANSFER_ID commands.

  4. Send the volume transfer ID and authorization key to the new owner (for example, by email).

  5. View pending transfers.

    $ cinder transfer-list
    | ID                                   | VolumeID                             | Name |
    |--------------------------------------|--------------------------------------|------|
    | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f | None |
    

    After the volume recipient, or new owner, accepts the transfer, the volume will not display in the transfer list.

To accept a volume transfer request:

  1. Obtain the transfer ID and authorization key from the original owner.

  2. Run cinder transfer-accept <transferID> <authKey> to accept the request.

    $ cinder transfer-accept 6e4e9aa4-bed5-4f94-8f76-df43232f44dc   b2c8e585cbc68a80
    | Property  | Value                                |
    |-----------|--------------------------------------|
    | id        | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc |
    | name      | None                                 |
    | volume_id | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f |
    

    Note
    If you do not have a sufficient quota for the transfer, the transfer is refused.

To delete a volume transfer:

  1. List available volumes and their statuses. Ensure the volume transfer you are deleting is awaiting-transfer.

    $ openstack volume list
    | ID                                   | Display Name | Status    | Size | Attached to |
    |--------------------------------------|--------------|-----------|------|-------------|
    | 2c52eb67-8974-4f0a-a881-305ae3bb778f | interop-vol  | available |    3 |             |
    | 03591e61-bbde-49be-ba3d-30b1b8285f8a | block-test   | awaiting-transfer |    3 |             |
    
    
  2. Locate the matching transfer ID.

    $ cinder transfer-list
    | ID                                   | VolumeID                             | Name |
    |--------------------------------------|--------------------------------------|------|
    | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f | None |
    
  3. Run cinder transfer-delete transferID to delete the volume.

    $ cinder transfer-delete 6e4e9aa4-bed5-4f94-8f76-df43232f44dc
    
  4. Verify that transfer list is now empty and that the volume is again available for transfer.

    $ cinder transfer-list  
    | ID | Volume ID | Name |
    |----|-----------|------|
    
    $ openstack image list  
    | ID                                   | Name                               | Status |
    |--------------------------------------|------------------------------------|--------|
    | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc | Windows10-3                        | active |
    | 68db6198-89e7-4567-a3a3-229467b77cda | ubuntu_1204_server_cloudimg_amd64  | active |
    | a4a38ada-8a11-4259-9b4f-3606634f6e92 | test-my-first-snapshot             | active |
    | db0ff7c8-d6af-42da-b841-99eb9c300368 | Ubuntu-Server-16.04-CloudImage-raw | active |