Creating and attaching a Cinder volume to an OpenStack instance

Using openstack-cli tools, let’s create a new 1GB cinder volume with a display name of repvolume

[root@localhost ~(keystone_demo)]# cinder create 1 --display-name repvolume
+---------------------+--------------------------------------+
| Property | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| created_at | 2015-09-16T15:59:45.025134 |
| display_description | None |
| display_name | repvolume |
| encrypted | False |
| id | 4efa3212-55bc-417d-a8ed-e88fa63f05d3 |
| metadata | {} |
| multiattach | false |
| size | 1 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| volume_type | None |
+---------------------+--------------------------------------+

Check if the volume was created successfully

[root@localhost ~(keystone_demo)]# cinder list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| 4efa3212-55bc-417d-a8ed-e88fa63f05d3 | available | repvolume | 1 | - | false | |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+

Let’s try to attach repvolume to one of our instance.

[root@localhost ~(keystone_demo)]# nova list
+--------------------------------------+----------+---------+------------+-------------+------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+----------+---------+------------+-------------+------------------+
| 38b5a3e7-e540-42fb-a25f-ea6e79c4d372 | client01 | ACTIVE | - | Running | private=10.0.0.6 |
| 431ba9e5-616c-401e-8dd6-e8269420246c | web01 | SHUTOFF | - | Shutdown | private=10.0.0.3 |
| 99584428-2d5d-4d3d-bd19-5a7a77cb7f24 | web02 | SHUTOFF | - | Shutdown | private=10.0.0.4 |
+--------------------------------------+----------+---------+------------+-------------+------------------+

Using client01 instance ID and the repvolume ID, let’s attach the cinder volume to our instance by issuing the following command.

[root@localhost ~(keystone_demo)]# nova volume-attach 38b5a3e7-e540-42fb-a25f-ea6e79c4d372 4efa3212-55bc-417d-a8ed-e88fa63f05d3 auto
+----------+--------------------------------------+
| Property | Value |
+----------+--------------------------------------+
| device | /dev/vdb |
| id | 4efa3212-55bc-417d-a8ed-e88fa63f05d3 |
| serverId | 38b5a3e7-e540-42fb-a25f-ea6e79c4d372 |
| volumeId | 4efa3212-55bc-417d-a8ed-e88fa63f05d3 |
+----------+--------------------------------------+

Issuing cinder list again should show that our volume is attached to client01

[root@localhost ~(keystone_demo)]# cinder list
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
| 4efa3212-55bc-417d-a8ed-e88fa63f05d3 | in-use | repvolume | 1 | - | false | 38b5a3e7-e540-42fb-a25f-ea6e79c4d372 |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+

Next let’s login to client01.

Issue lsblk to see the available block device.  Since this is a new block device, we need to format it

mkfs.ext4 /dev/vdb

Now let’s create a new directory where we could mount the new volume.

mkdir /repvolume

Using the mount command, let’s mount the device.

mount /dev/vdb /repvolume

Issuing df command should show the new volume