(Last Updated On: September 17, 2019)

How can I create Cinder Volumes in OpenStack and attach to an Instance?. OpenStack Cinder service provides persistent block storage management for virtual hard drives. Through the OpenStack CLI and Horizon Web interface, you can manage the creation, attaching, and detaching of the block devices to servers. In this guide, we will discuss how you can create, attach and detach Cinder Volumes to Servers running in an OpenStack environment.

You need to have configured OpenStack CLI for this guide to be relevant. We have a separate article on How To Install and Configure OpenStack Client on Linux. Refer to it for installation and configuration of OpenStack Client on a Linux system.

Step 1: Check OpenStack Cinder Services

Once OpenStack Client is set, check to confirm all the Cinder services are running. Cinder is composed of the following:

  • openstack-cinder-volume, which carves out storage for virtual machines on demand. A number of drivers are provided for interaction with storage providers.
  • openstack-cinder-api, which responds to and handles requests, and places them in the message queue.
  • openstack-cinder-scheduler, which assigns tasks to the queue and determines the provisioning volume server.

Use the following command to confirm state of these services.

for i in volume api scheduler; do
 systemctl status openstack-cinder-$i
done

Sample output – All status should be running.

......
● openstack-cinder-volume.service - OpenStack Cinder Volume Server
    Loaded: loaded (/usr/lib/systemd/system/openstack-cinder-volume.service; enabled; vendor preset: disabled)
    Active: active (running) since Sat 2019-09-07 10:13:38 EAT; 14min ago
  Main PID: 6427 (cinder-volume)
     Tasks: 2
    CGroup: /system.slice/openstack-cinder-volume.service
            ├─6427 /usr/bin/python2 /usr/bin/cinder-volume --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf…
            └─6468 /usr/bin/python2 /usr/bin/cinder-volume --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf…

...............
● openstack-cinder-api.service - OpenStack Cinder API Server
    Loaded: loaded (/usr/lib/systemd/system/openstack-cinder-api.service; enabled; vendor preset: disabled)
    Active: active (running) since Sat 2019-09-07 10:13:42 EAT; 14min ago
  Main PID: 6599 (cinder-api)
     Tasks: 9
    CGroup: /system.slice/openstack-cinder-api.service
            ├─6599 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6691 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6692 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6693 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6694 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6695 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6696 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6697 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            └─6699 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…

......................
● openstack-cinder-scheduler.service - OpenStack Cinder Scheduler Server
    Loaded: loaded (/usr/lib/systemd/system/openstack-cinder-scheduler.service; enabled; vendor preset: disabled)
    Active: active (running) since Sat 2019-09-07 10:13:46 EAT; 14min ago
  Main PID: 6792 (cinder-schedule)
     Tasks: 1
    CGroup: /system.slice/openstack-cinder-scheduler.service
            └─6792 /usr/bin/python2 /usr/bin/cinder-scheduler --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.c…

Step 2: Create Cinder Volume

You need to have configured a Cinder storage backend and confirmed to be working. I use LVM backend in my setup.

$ pvs | grep cinder
  /dev/nvme0n1p1 cinder-volumes lvm2 a--  <476.94g   23.59g

$ vgs | grep cinder
  cinder-volumes   1   4   0 wz--n- <476.94g   23.59g

Create a Cinder Volume using below command Syntax.

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

Where:

  • <size> is the Volume size in GB
  • <name> is the name of the volume to be created.

Below example will create a volume called c4geeks-db-backups of size 30GB

$ openstack volume create --size 30 c4geeks-db-backups

+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attachments         | []                                   |
| availability_zone   | nova                                 |
| bootable            | false                                |
| consistencygroup_id | None                                 |
| created_at          | 2019-09-07T07:37:14.000000           |
| description         | None                                 |
| encrypted           | False                                |
| id                  | 4a4f5cf1-9122-4147-83c1-5aa622f7ba57 |
| migration_status    | None                                 |
| multiattach         | False                                |
| name                | c4geeks-db-backups                   |
| properties          |                                      |
| replication_status  | None                                 |
| size                | 30                                   |
| snapshot_id         | None                                 |
| source_volid        | None                                 |
| status              | creating                             |
| type                | None                                 |
| updated_at          | None                                 |
| user_id             | 336acbb7421f47f8be4891eabf0c9cc8     |
+---------------------+--------------------------------------+

Confirm Volume creation state.

$ openstack volume list
+--------------------------------------+---------------------+----------------+------+--------------------------------------+
| ID                                   | Name                | Status         | Size | Attached to                          |
+--------------------------------------+---------------------+----------------+------+--------------------------------------+
| 4a4f5cf1-9122-4147-83c1-5aa622f7ba57 | c4geeks-db-backups  | available      |   30 |                                      |
+--------------------------------------+---------------------+----------------+------+--------------------------------------+

We can confirm the Volume of size 30GB has been created successfully and is ready for use. Let’s attach it to a server running on OpenStack.

But first, pull the Virtual Machine name/ID

$ openstack server list
+--------------------------------------+-------------------+--------+-----------------------------------+----------+-----------+
| ID                                   | Name              | Status | Networks                          | Image    | Flavor    |
+--------------------------------------+-------------------+--------+-----------------------------------+----------+-----------+
| 08df4929-4d9e-4881-9f01-6d89e9862385 | c4geeks-db-server | ACTIVE | private=10.10.1.196               | CentOS-7 | m1.large  |
+--------------------------------------+-------------------+--------+-----------------------------------+----------+-----------+

Attach created Volume to the server.

openstack server add volume c4geeks-db-server c4geeks-db-backups 

Check Cinder Volumes attachment.

$ openstack volume list
+--------------------------------------+---------------------+----------------+------+--------------------------------------------+
| ID                                   | Name                | Status         | Size | Attached to                                |
+--------------------------------------+---------------------+----------------+------+--------------------------------------------+
| 4a4f5cf1-9122-4147-83c1-5aa622f7ba57 | c4geeks-db-backups  | in-use         |   30 | Attached to c4geeks-db-server on /dev/vdc  |
+--------------------------------------+---------------------+----------------+------+--------------------------------------------+

Step 3: Consume Cinder Volume on a Virtual Machine

Login to your server and check if raw block device is visible.

$ lsblk /dev/vdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdc  253:32   0  30G  0 disk 

Let’s now partition and mount it.

sudo parted -s -a optimal -- /dev/vdc mklabel gpt
sudo parted -s -a optimal -- /dev/vdc mkpart primary 0% 100%
sudo parted -s -- /dev/vdc align-check optimal 1
sudo mkfs.xfs /dev/vdc1
sudo mkdir /data
echo "/dev/vdc1 /data xfs defaults 0 0" | sudo tee -a /etc/fstab
sudo mount -a

View current mount map.

$ df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      xfs        40G  2.6G   38G   7% /
devtmpfs       devtmpfs  3.8G     0  3.8G   0% /dev
tmpfs          tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs          tmpfs     3.9G   17M  3.9G   1% /run
tmpfs          tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs          tmpfs     783M     0  783M   0% /run/user/1000
/dev/vdc1      xfs        30G   33M   30G   1% /data

Start utilizing added Block storage in your daily operations.

Detaching Cinder Virtual Disk from server

To detach and delete the disk, unmount it on the server, then run:

openstack server remove volume c4geeks-db-server c4geeks-db-backups
openstack volume delete c4geeks-db-backups

Check other OpenStack tutorials available in our blog.

Best books for Learning OpenStack Cloud Platform 2019

How To Resize OpenStack Instance / Virtual Machine

OpenStack Deployment on CentOS 7 With Packstack

How To Install and Configure OpenStack Client on Linux

OpenStack Deployment on Ubuntu 18.04 with DevStack

How To add Glance Cloud images to OpenStack

Adding ssh key pair to Openstack using cli

How to add flavors to openstack using cli