A volume is a detachable block storage device (as a usb hard drive). This allows for persistent storage.

How to manage a volume?

By using openstack volume list comand line, you can list existing volumes.

Create a volume

To create a volume, use the following command line

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

You can create a volume from different types of sources.
It depends on the option you choose when creating the volume :

  • default (no option) : to create a non-bootable volume,
  • from an image - [--image <image>] : often used to create a boot volume for an instance,
  • from a snapshot - [--snapshot <snapshot>] of an instance,
  • from another volume - [--source <volume>] : to clone a volume,
  • from a replicated volume - [--source-replicated <replicated-volume>] : to clone a replica.

If you build a volume from a specified source then you don’t need to specify the size.

Resize a volume

To resize a volume, specify the ID (or the name) of the volume and a size (--size) larger than the old one.

The volume must not be attached to an instance.

$ openstack volume set <volume> --size <new-size>

Note that this command does not return any output but you can check the new volume size by displaying its information.

Delete a volume

Specify the ID (or name) of the volume and delete it using

$ openstack volume delete <volume>

Before deleting, make sure that an instance is not attached to the volume.

To verify that the volume is deleted, list the volumes.

$ openstack volume list

The volume should have the following status: status = deleting.
DeleteVolume When completely deleted, it disappears from the list.
Please note that if the volume was not significant size, you may not have had time to see it appear in a deleted state in the volume list.

Volume and instance

Volumes can be attached and detached to instances at any time.

A volume can be attached to only one instance.

Attach a volume to instance

To attach a volume to an instance, please use openstack server add volume.
Then specify the ID or name for instance and volume.

$ openstack server add volume <instance> <volume> 

Note that this command produces no output.
But you can check if the volume is properly attached to an instance by displaying its information.

$ openstack volume show <volume>


Detach a volume from instance

To detach a volume from instance, specify ID or name for instance and volume.

$ openstack server remove volume <instance> <volume> 

Then display its information to check if it is no longer attached.

$ openstack volume show <volume>

Attachments line must be empty (attachments = []). VolumeDissociate