How to create cinder volume in Openstack

In this tutorial we will see, How to create cinder volume in Openstack? How to attach, detach and delete cinder volume from Openstack instance? So first off all we should know what is cinder volume? Why we need it in Openstack?

What is Block storage (cinder) volume?

Cinder is a block storage service in Openstack, which provide block storage devices for our virtual machine (instance). If we need to additional disk in our virtual machine then we can create one cinder volume as per our requirement size and we will attach this cinder volume in any instance where we want to attach it. We can also create bootable cinder volume as per our requirement.

In this tutorial we will see following steps:-

  1. Create cinder volume in Openstack.
  2. Attach cinder volume in instance (Virtual Machine).
  3. Detach cinder volume from instance (Virtual Machine).
  4. Delete cinder volume in Openstack.

Create cinder volume in Openstack

So let’s start first create the cinder volume. We can use Openstack volume create command to create cinder volume. You can see below command output for example

Command: – openstack volume create –size 1 <volume-name>

I am creating 1GB volume where test-volume1 is name of volume.

[email protected]:~$ openstack volume create --size 1 test-volume1
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attachments         | []                                   |
| availability_zone   | nova                                 |
| bootable            | false                                |
| consistencygroup_id | None                                 |
| created_at          | 2018-08-07T06:30:32.016181           |
| description         | None                                 |
| encrypted           | False                                |
| id                  | ac88b63e-fd9e-4436-bb4a-149fc667542e |
| migration_status    | None                                 |
| multiattach         | False                                |
| name                | test-volume1                         |
| properties          |                                      |
| replication_status  | disabled                             |
| size                | 1                                    |
| snapshot_id         | None                                 |
| source_volid        | None                                 |
| status              | creating                             |
| type                | None                                 |
| updated_at          | None                                 |
| user_id             | 6f0e3f0521524a0e9469112bdb45635c     |
+---------------------+--------------------------------------+
[email protected]:~$

It will take some time to create a volume. Once volume will be successfully created then it will show available otherwise you will see creating status. You can check with Openstack volume list commands. You can see in below we have successfully volume create and available.

[email protected]:~$ openstack volume list
+--------------------------------------+-------------------+-----------+------+---------------------------------------+
| ID                                   | Display Name      | Status    | Size | Attached to                           |
+--------------------------------------+-------------------+-----------+------+---------------------------------------+
| ac88b63e-fd9e-4436-bb4a-149fc667542e | test-volume1      | available |    1 |                                       |
+--------------------------------------+-------------------+-----------+------+---------------------------------------+
[email protected]:~$

Attach cinder volume in instance

After that we can attach this volume in any instance (Virtual Machine). So I am attaching test-volume1  with cirros instance and show you how to attach cinder volume in instance.

#Command:-openstack server add volume INSTANCE_NAME VOLUME_NAME

[email protected]:~$ openstack server add volume cirros test-volume1
[email protected]:~$

You can see above we have attached test-volume1 with cirros instance. Now let’s verify it with Openstack volume list command and see attach status.

[email protected]:~$ openstack volume list
+--------------------------------------+-------------------+--------+------+---------------------------------------+
| ID                                   | Display Name      | Status | Size | Attached to                           |
+--------------------------------------+-------------------+--------+------+---------------------------------------+
| ac88b63e-fd9e-4436-bb4a-149fc667542e | test-volume1      | in-use |    1 | Attached to cirros on /dev/vdb        |
+--------------------------------------+-------------------+--------+------+---------------------------------------+
[email protected]:~$

You can see above our test-volume1 has been successfully attached with cirros instance.

Now we need to go to our instance and check our volume is added or not?

Login with SSH on your instance and check with sudo fdisk –l command then you will find output like below.

$ sudo fdisk -l


Disk /dev/vda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *       16065    10474379     5229157+  83  Linux


Disk /dev/vdb: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/vdb doesn't contain a valid partition table

$

You can see in above we have successfully added /dev/vdb disk with 1 GB space in bold letter.

You can see in above we have successfully added /dev/vdb disk with 1 GB space in bold letter.

If you want to use this /dev/vdb disk then first off all you have to create file system and mount your file system in instance then you can use this disk.

You can follow this link to create file system and mount partition in your RHEL 7 or CentOS 7 instance.

Disk partitions and mounting in CentOS 7

Detach cinder volume from instance

If you want to detach your volume from instance then you have to run this commands:-

#Command:- openstack server remove volume <instance-name>  <volume-name>

[email protected]:~$ openstack server remove volume cirros test-volume1
[email protected]:~$

Now you can see in above output we have removed successfully test-volume1 from cirros instance.

Display the volume list to verify detached status like below output.

[email protected]:~$ openstack volume list
+--------------------------------------+-------------------+-----------+------+---------------------------------------+
| ID                                   | Display Name      | Status    | Size | Attached to                           |
+--------------------------------------+-------------------+-----------+------+---------------------------------------+
| ac88b63e-fd9e-4436-bb4a-149fc667542e | test-volume1      | available |    1 |                                       |
+--------------------------------------+-------------------+-----------+------+---------------------------------------+
[email protected]:~$

You can see in above output our attached volume /dev/vdb has been detached from cirros instance.

Now verify detach volume from instance side. We can login our instance and run fdisk -l to check our attached volume has been detached or not?

$ sudo fdisk -l


Disk /dev/vda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *       16065    10474379     5229157+  83  Linux
$

You can see in above output we have successfully detached our volume /dev/vdb from instance side.

Delete cinder volume from Openstack

If you want to remove your volume then you have to run this command:-

#Command:- openstack volume delete <volume-name>

[email protected]:~$ openstack volume delete test-volume1
[email protected]:~$

You can see in above output we have successfully removed our test-volume1.

Now we can verify test-volume1 with Openstack volume list command, test-volume1 has been deleted or not?

[email protected]:~$ openstack volume list
+--------------------------------------+-------------------+--------+------+---------------------------------------+
| ID                                   | Display Name      | Status | Size | Attached to                           |
+--------------------------------------+-------------------+--------+------+---------------------------------------+
+--------------------------------------+-------------------+--------+------+---------------------------------------+
[email protected]:~$

You can see in above output we have successfully deleted cinder volume.

That’s all, In this tutorial we have seen step by step, cinder volume creation, cinder volume attached and detached from instance and cinder volume deletion from Openstack. 

Increase default Nova quota in Openstack

1 thought on “How to create cinder volume in Openstack

  1. I haven’t checked in here for a while because I thought it was getting boring, but the last few posts are great quality so I guess I’ll add you back to my everyday bloglist. You deserve it my friend 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *