Managing Volumes Using the CLI

A volume is a detachable Block Storage device. You can create an empty volume or a volume from a specific source: image, volume, volume snapshot.

Source Command
empty $ openstack volume create <VOLUME_NAME> --size <SIZE>
image $ openstack volume create <VOLUME_NAME> --size <SIZE> --image <IMAGE_ID>
volume $ openstack volume create <VOLUME_NAME> --size <SIZE> --source <VOLUME_ID>
snapshot $ openstack volume create <VOLUME_NAME> --size <SIZE> --snapshot <SNAPSHOT_ID>

Once you create a volume, you can use it to boot a new instance or attach it to an existing instance. A volume can only be attached to one instance. You must detach a volume from an instance to use with another instance or to delete the volume.

Note
For details on using different methods to create a volume and boot an instance, see Launching an Instance from a Volume.

To see a list of available volume types:

You can specify a volume type when you create a volume with the --type option. The volume types available depend on your Metacloud deployment configuration. For more information on storage, see Working with Block Storage.

$ openstack volume type list
+---------------+------+-----------+
| ID            | Name | Is Public |
+---------------+------+-----------+
| <type_id>     | ceph | True      |
+---------------+------+-----------+

To create a volume based on an image:

  1. List images and note the ID of the image source.

    $ openstack image list
    
  2. Create a volume by specifying the image source and the volume size in GB to accommodate the image. You can specify an availability zone by including the --availability-zone option.

    $ openstack volume create VOL1 --size 20 --image <IMAGE_ID>
    +---------------------+------------------------------+
    | Field               | Value                        |
    +---------------------+------------------------------+
    | attachments         | []                           |
    | availability_zone   | <AZ>                         |
    | bootable            | false                        |
    | consistencygroup_id | None                         |
    | created_at          | 2017-01-23T23:15:06.300766   |
    | description         | None                         |
    | encrypted           | False                        |
    | id                  | <volume_id>                  |
    | multiattach         | False                        |
    | name                | VOL1                         |
    | properties          |                              |
    | replication_status  | disabled                     |
    | size                | 20                           |
    | snapshot_id         | None                         |
    | source_volid        | None                         |
    | status              | creating                     |
    | type                | None                         |
    | user_id             | <user_id>                    |
    +---------------------+------------------------------+
    
  3. Verify the volume exists and the status is available. The volume status is creating until the create operation is complete.

    $ openstack volume list
    +---------------+--------------+-----------+------+-------------+
    | ID            | Display Name | Status    | Size | Attached to |
    +---------------+--------------+-----------+------+-------------+
    | <volume_id>   | VOL1         | available |   20 |             |
    | <volume_id>   | block-test   | available |    3 |             |
    +---------------+--------------+-----------+------+-------------+
    
  4. Attach the volume to an instance.

    $ openstack server add volume instance01 VOL1
    
    

To detach a volume from an instance:

Some volume actions are not available if the volume status is in-use or attached to an instance. For example, you cannot delete a volume, extend a volume, or create a snapshot of a volume until you detach it from the instance.

  1. List the volumes. The “Attached to” column identifies the attachment to a specific instance.

    $ openstack volume list
    +---------------+--------------+-----------+------+-----------------------------------+
    | ID            | Display Name | Status    | Size | Attached to                       |
    +---------------+--------------+-----------+------+-----------------------------------+
    | <volume_id>   | VOL1         | in-use    |   20 | Attached to instance01 on /dev/vdb|
    | <volume_id>   | block-test   | available |    3 |                                   |
    +---------------+--------------+-----------+------+-----------------------------------+
    
  2. Detach the the volume from the instance.

    $ openstack server remove volume instance01 VOL1
    
  3. Verify the volume detached from the instance by listing the volumes again and checking the Attached to column is now empty.

To snapshot a volume:

There is a limit to the amount of volume snapshots and the total size available for volumes within your project. Consult your administrator if you are not able to create a volume snapshot.

Note
You cannot create a volume snapshot when using the NFS storage system.

  1. Create a snapshot of the volume.

    $ openstack volume snapshot create snapshotVOL1 --volume VOL1
    +-------------+--------------------------------------+
    | Field       | Value                                |
    +-------------+--------------------------------------+
    | created_at  | 2017-01-27T14:57:16.777753           |
    | description | None                                 |
    | id          | 37fcdc77-9...                        |
    | name        | snapshotVOL1                         |
    | properties  |                                      |
    | size        | 10                                   |
    | status      | creating                             |
    | volume_id   | <volume_id>                          |
    +-------------+--------------------------------------+
    
  2. Verify the snapshot exists and the status is available. The snapshot status is creating until the create operation is complete.

    $ openstack volume snapshot list
    +---------------+--------------+-------------+-----------+------+
    | ID            | Name         | Description | Status    | Size |
    +---------------+--------------+-------------+-----------+------+
    | <snap_id>     | snapshotVOL1 | None        | available |   20 |
    +---------------+--------------+-------------+-----------+------+
    

To extend a volume:

You can extend a volume by changing the size attribute with the openstack volume set command. In the current example, volume VOL1 is size 20. To extend VOL1 to size 30: $ openstack volume set VOL1 --size 30

To delete a volume:

You can delete a volume if it is not attached to an instance.

  1. Delete the volume.

    $ openstack volume delete VOL1
    
  2. Verify the volume deleted successfully. The volume status is deleting until the delete operation is complete.