A volume is a detachable block storage device (as a usb hard drive). This allows for persistent storage.
By using openstack volume list
comand line, you can list existing volumes.
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 :
--image <image>
] : often used to create a boot volume for an instance,--snapshot <snapshot>
] of an instance,--source <volume>
] : to clone a 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.
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.
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.
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.
Volumes can be attached and detached to instances at any time.
A volume can be attached to only one 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>
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 = []).