Managing Volumes

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 |
    |--------------|---------------------------------------|--------|
    | <image_id>   | Windows10-3                           | active |
    | <image_id>   | ubuntu_1204_server_cloudimg_amd64     | active |
    | <image_id>   | test-my-first-snapshot                | active |
    | <image_id>   | Ubuntu-Server-16.04-CloudImage-raw    | active |
    
    
  2. List availability zones and note the Zone Name of the AZ to create your volume.

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

    $ openstack volume create <VOLUME_NAME> --size <SIZE> --image <IMAGE_ID> --availability-zone <AZ>
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | attachments         | []                                   |
    | availability_zone   | <az_name>                            |
    | bootable            | false                                |
    | consistencygroup_id | None                                 |
    | created_at          | 2017-05-15T19:22:20.562347           |
    | description         | None                                 |
    | encrypted           | False                                |
    | id                  | <volume_id>                          |
    | migration_status    | None                                 |
    | multiattach         | False                                |
    | name                | <volume_name>                        |
    | properties          |                                      |
    | replication_status  | disabled                             |
    | size                | 8                                    |
    | snapshot_id         | None                                 |
    | source_volid        | None                                 |
    | status              | creating                             |
    | type                | ceph                                 |
    | user_id             | <user_id>                            |
    +---------------------+--------------------------------------+
    
    
  4. Verify that your volume was created successfully.

    $ openstack volume list
    | ID           | Display Name    | Status    | Size | Attached to |
    |--------------|-----------------|-----------|------|-------------|
    | <volume_id>  | my-new-volume   | available | 8    |             |
    | <volume_id>  | 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.

To create a volume using a Volume Type:

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

    $ openstack volume create --name <VOLUME_NAME> --volume-type <VOLUME_TYPE> <SIZE>
    

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

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

    $ openstack image list
    | ID           | Name                               | Status |
    |--------------|------------------------------------|--------|
    | <image_id>   | Windows10-3                        | active |
    | <image_id>   | ubuntu_1204_server_cloudimg_amd64  | active |
    | <image_id>   | test-my-first-snapshot             | active |
    | <image_id>   | Ubuntu-Server-16.04-CloudImage-raw | active |
    
  3. Create the volume.

    $ openstack volume create <VOLUME_NAME> --image <IMAGE_ID> --size <SIZE> --availablilty zone <AZ> --type <VOLUME_TYPE>
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | attachments         | []                                   |
    | availability_zone   | stage1                               |
    | bootable            | false                                |
    | consistencygroup_id | None                                 |
    | created_at          | 2017-05-15T20:32:25.386999           |
    | description         | None                                 |
    | encrypted           | False                                |
    | id                  | <volume_id>                          |
    | migration_status    | None                                 |
    | multiattach         | False                                |
    | name                | EXAMPLE1                             |
    | properties          |                                      |
    | replication_status  | disabled                             |
    | size                | 3                                    |
    | snapshot_id         | None                                 |
    | source_volid        | None                                 |
    | status              | creating                             |
    | type                | ceph                                 |
    | user_id             | <user_id>                            |
    +---------------------+--------------------------------------+
    

To attach a volume to an instance:

  1. Attach your volume to a server.

    $ openstack server add volume <INSTANCE_ID> <VOLUME_ID> --device <DEVICE_NAME>
    

    Note the ID of your volume.

  2. Show information for your volume.

    $ openstack volume show <VOLUME_ID>
    
    +---------------------------------------+-------------------------------------------------------------------------------------------+
    | Field                                 | Value                                                                                     |
    +---------------------------------------+-------------------------------------------------------------------------------------------+
    | attachments                           | [{u'server_id': u'<server_id>', u'attachment_id': u'<attachment_id>',u'host_name': None,  |
    |                                       | u'volume_id': u'<volume_id>', u'device': u'/dev/vdb', u'id': u'<volume_id>'}]             |
    | availability_zone                     | stage1                                                                                    |
    | bootable                              | false                                                                                     |
    | consistencygroup_id                   | None                                                                                      |
    | created_at                            | 2017-05-15T18:24:13.000000                                                                |
    | description                           | None                                                                                      |
    | encrypted                             | False                                                                                     |
    | id                                    | <volume_id>                                                                               |
    | migration_status                      | None                                                                                      |
    | multiattach                           | False                                                                                     |
    | name                                  | hg-test-vol                                                                               |
    | os-vol-host-attr:host                 | Host.AZ@volume-type#volume-type                                                           |
    | os-vol-mig-status-attr:migstat        | None                                                                                      |
    | os-vol-mig-status-attr:name_id        | None                                                                                      |
    | os-vol-tenant-attr:tenant_id          | <tenant_id>                                                                               |
    | os-volume-replication:driver_data     | None                                                                                      |
    | os-volume-replication:extended_status | None                                                                                      |
    | properties                            | attached_mode='rw', readonly='False'                                                      |
    | replication_status                    | disabled                                                                                  |
    | size                                  | 40                                                                                        |
    | snapshot_id                           | None                                                                                      |
    | source_volid                          | None                                                                                      |
    | status                                | in-use                                                                                    |
    | type                                  | ceph                                                                                      |
    | user_id                               | <user_id>                                                                                 |
    +---------------------------------------+-------------------------------------------------------------------------------------------+
    

To resize a volume:

  1. Detach the volume from your server.

    $ openstack server remove volume <INSTANCE_ID> <VOLUME_ID>
    

    The remove volume command does not return any output.

  2. List available volumes.

      $ openstack volume list
    | ID           | Display Name    | Status    | Size | Attached to |
    |--------------|-----------------|-----------|------|-------------|
    | <volume_id>  | my-new-volume   | available | 8    |             |
    | <volume_id>  | my-bootable-vol | available | 8    |             |
    
    
    
  3. Resize the volume.

    $ cinder extend <VOLUME_ID> <SIZE>
    

    The extend command does not return any output.

To delete a volume:

  1. Detach the volume from your server.

    $ openstack server remove volume <INSTANCE_ID> <VOLUME_ID>
    
  2. Delete the volume using either the volume name or ID.

    $ openstack volume delete <VOLUME_ID>
    

    The delete command does not return any output.

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

    $ openstack volume list
    | ID           | Display Name    | Status    | Size | Attached to |
    |--------------|-----------------|-----------|------|-------------|
    | <volume_id>  | my-new-volume   | deleting  | 8    |             |
    | <volume_id>  | my-bootable-vol | available | 8    |             |
    | <volume_id>  | cloudimg_amd64  | available | 8    |             |
    

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

      $ openstack volume list
    | ID           | Display Name    | Status    | Size | Attached to |
    |--------------|-----------------|-----------|------|-------------|
    | <volume_id>  | my-bootable-vol | available | 8    |             |
    | <volume_id>  | cloudimg_amd64  | available | 8    |             |