Create and manage volumes

Last changed: 2019-08-05

Volumes are block storage devices that you attach to instances to enable persistent storage. You can attach a volume to a running instance or detach a volume and attach it to another instance at any time. You can also create a snapshot from or delete a volume.

Create a volume

In the dashboard, select Volumes in the Volumes tab:

Dashboard - Volumes -> Volumes

Click on Create Volume, and the following window appears:

Dashboard - Create Volume

Fill in the form:

  • Volume Name: A name for the volume, which you will recognize (Required)
  • Description: An optional description
  • Volume Source: Either no source, i.e. an empty volume, or create a volume from an image
  • Type: You can leave this empty
  • Size: The size of the volume, in GB
  • Availability Zone: Choose “nova”

Then click Create Volume. The volume will be instantly created and available:

Dashboard - Create Volume finished

You can also Create Snapshot of the volume. The snapshot of the volume will be located under Volumes tab:

Dashboard - Volumes -> Snapshots

Attach a volume to a virtual machine

After creating one or more volumes, you can attach them to virtual machines (instances). A volume is a block storage device, and can only be attached to one virtual machine at a time. In the Volumes tab under Volumes, select Manage Attachments from the dropdown menu:

Dashboard - Attach volume

Select the virtual machine (instance) that you wish to attach this volume to. You usually don’t need to change the device name. Then click on Attach Volume.

Dashboard - Attach volume part 2

The volume is now attached to the virtual machine.

Dashboard - Attach volume finished

The volume can now be used as a regular block device from within the virtual machine (example):

If this is the first time using this volume, you need to create a file system on it.
Check if there is already an available block device:
# lsblk
NAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
vda    253:0    0      1G  0 disk
`-vda1 253:1    0 1011.9M  0 part /
vdb    253:16   0     10G  0 disk

If there are not any file systems, you need to create one:
# mkfs.ext4 /dev/vdb
[...]

Create a folder and mount the volume on it:
# mkdir /persistent01 && mount /dev/vdb /persistent01

Check the amount of disk space available on the file system, and start storing data:
# df -h /persistent01
Filesystem                Size      Used Available Use% Mounted on
/dev/vdb                  9.8G    150.5M      9.2G   2% /persistent01

Note that in order for the volume to be mounted automatically after a reboot, you will have to add an entry to /etc/fstab.

Detach a volume from a virtual machine

In order to detach a volume from a virtual machine (instance), select Manage Attachments from the dropdown menu in the Volumes:

Dashboard - Detach volume

Select the attachment and click on Detach Volume:

Dashboard - Detach volume part 2

You will have to confirm this action. Click Detach Volume in the confirmation dialog that appears:

Dashboard - Detach volume confirmation

The volume is now detached.

Delete a volume

Deleting a volume is pretty straightforward. In the Volumes, select the appropriate check boxes for the volumes that you want to delete, and click Delete Volumes:

Dashboard - Delete volumes

Then confirm your choice, click Delete Volumes:

Dashboard - Delete volumes confirmation

The volume is then deleted.

Doing the same with CLI

  1. Creating the volume:

    $ openstack volume create --size 10 --description "A test volume" mytestvolume
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | attachments         | []                                   |
    | availability_zone   | nova                                 |
    | bootable            | false                                |
    | consistencygroup_id | None                                 |
    | created_at          | 2016-11-11T15:41:00.171512           |
    | description         | A test volume                        |
    | encrypted           | False                                |
    | id                  | a7234dda-a97a-44c3-aa93-9b2952fd2bcf |
    | multiattach         | False                                |
    | name                | mytestvolume                         |
    | properties          |                                      |
    | replication_status  | disabled                             |
    | size                | 10                                   |
    | snapshot_id         | None                                 |
    | source_volid        | None                                 |
    | status              | creating                             |
    | type                | None                                 |
    | updated_at          | None                                 |
    | user_id             | 6bb8dbcdc9b94fff89258094bc56a49f     |
    +---------------------+--------------------------------------+
    
  2. Listing the servers and volumes:

    $ openstack volume list
    +--------------------------------------+--------------+-----------+------+-------------+
    | ID                                   | Display Name | Status    | Size | Attached to |
    +--------------------------------------+--------------+-----------+------+-------------+
    | a7234dda-a97a-44c3-aa93-9b2952fd2bcf | mytestvolume | available |   10 |             |
    +--------------------------------------+--------------+-----------+------+-------------+
    
    $ openstack server list
    +--------------------------------------+----------+--------+----------------------+------------+
    | ID                                   | Name     | Status | Networks             | Image Name |
    +--------------------------------------+----------+--------+----------------------+------------+
    | 5a102c14-83fd-4788-939e-bb2e635e49de | myserver | ACTIVE | public=158.39.77.147 | Fedora 24  |
    +--------------------------------------+----------+--------+----------------------+------------+
    
  3. Attaching the volume to the server:

    $ openstack server add volume myserver mytestvolume
    

    You may also use the IDs of the server and volume instead of the names.

  4. Confirming that the volume is attached:

    $ openstack volume list
    +--------------------------------------+--------------+--------+------+-----------------------------------+
    | ID                                   | Display Name | Status | Size | Attached to                       |
    +--------------------------------------+--------------+--------+------+-----------------------------------+
    | a7234dda-a97a-44c3-aa93-9b2952fd2bcf | mytestvolume | in-use |   10 | Attached to myserver on /dev/vdb  |
    +--------------------------------------+--------------+--------+------+-----------------------------------+
    
  5. Detaching the volume:

    $ openstack server remove volume myserver mytestvolume
    
  6. Deleting the volume:

    $ openstack volume delete mytestvolume
    
  7. Confirming that the volume is deleted:

    $ openstack volume list