How to Create Volumes in OpenStack

Volumes are a way you can have extra storage for your VM instances. You can think of them as an external storage device like a hard drive or USB drive that you can freely attach and detach from your VM. Your project has a set quota on how much space you can have on your volumes and how how many volumes you can make. You can create volumes anytime you like (you don't have to be creating a VM, so the volume creation is independent). You can snapshot a volume, which is a way to copy the file content of a volume into a new volume. You can also make an existing volume larger after than its creation.

The following is a guide on how to create volumes in OpenStack based on the official guide (https://docs.openstack.org/horizon/latest/user/manage-volumes.html), added with screenshots. 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. Only administrative users can create volume types.

Creating a volume

  1. Log in to the dashboard.

  2. Select the appropriate project from the drop down menu at the top left.

  3. On the Project tab, open the Volumes tab and click Volumes category.

  4. Click Create Volume. A pop up will appear.

    In the dialog box that opens, enter or select the following values.

    Volume Name: Specify a name for the volume.

    Description: Optionally, provide a brief description for the volume.

    Volume Source: Select one of the following options:

    • No source, empty volume: Creates an empty volume. An empty volume does not contain a file system or a partition table.
    • Snapshot: If you choose this option, a new field for Use snapshot as a source displays. You can select the snapshot from the list.
    • Image: If you choose this option, a new field for Use image as a source displays. You can select the image from the list.
    • Volume: If you choose this option, a new field for Use volume as a source displays. You can select the volume from the list. Options to use a snapshot or a volume as the source for a volume are displayed only if there are existing snapshots or volumes.

    Type: Leave this field blank.

    Size (GB): The size of the volume in gibibytes (GiB).

    Availability Zone: Select the Availability Zone from the list. By default, this value is set to the availability zone given by the cloud provider (for example, us-west or apac-south). For some cases, it could be nova.

  5. Click Create Volume. The pop up will disappear. The Volume page in the dashboard shows the volume on the Volumes tab. Confirm that the volume that you just created is in the list. On the rightmost column are buttons for actions that can be done on the volume.



  6. Here are the actions you can do:Actions that can be done if the volume is attached already:


  7. Actions that can be done if the volume is not attached to a VM:




Attaching a volume to an instance

After you create one or more volumes, you can attach them to instances. You can attach a volume to one instance at a time.

  1. Log in to the dashboard.

  2. Select the appropriate project from the drop down menu at the top left.

  3. On the Project tab, open the Volumes tab and click Volumes category.

  4. Select the volume to add to an instance and click Manage Attachments.

  5. In the Manage Volume Attachments dialog box, select an instance.

  6. Enter the name of the device from which the volume is accessible by the instance.
     

    Note:

    The actual device name might differ from the volume name because of hypervisor settings.

  7. Click Attach Volume.

    The dashboard shows the instance to which the volume is now attached and the device name.

You can view the status of a volume in the Volumes tab of the dashboard. The volume is either Available or In-Use.

Now you can log in to the instance and mount, format, and use the disk. To do the mounting, formatting, etc. you need to do some Linux-specific operations from inside your Linux VM.


Formatting a Volume for a Linux VM

After creating a volume in the OpenStack dashboard and attaching it to a VM, the volume is not yet ready to use. There are steps that need to be done from within the VM to allow you to read/write data into it.

The example below explains how to do the steps in a Linux VM (tested on Ubuntu 18.04).

The VM should see the volume as a device with a unique ID. You can get the ID by running this command. Below, the scenario is that we have previously created an OpenStack volume with size of 100G:

$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda     252:0    0   40G  0 disk 
├─vda1  252:1    0 39.9G  0 part /
├─vda14 252:14   0    4M  0 part 
└─vda15 252:15   0  106M  0 part /boot/efi
vdb     252:16   0   100G  0 disk 

In the example above, the device name is /dev/vdb (note that "/dev/" has been appended to "vdb"). It's important to remember this device name. The VM sees this volume as a disk (see the Type column above).

Now, format the disk so that it can be read and written to. Change /dev/deviceID to your volume's disk name:

Running mkfs on the wrong disk will erase existing data on that disk. You have to ensure the device name that you specified is correct. In this example, the disk device name is /dev/vdb, but your VM may have other names such as /dev/vdc, /dev/vdd, etc.


$ mkfs -t ext4 /dev/deviceID

Then, mount the formatted disk to a directory. In the example, the directory is "/mnt", but you can create your own custom directory:

$ mount /dev/deviceID /mnt

To check if the above steps were done correctly, run lsblk again to see that the device has the correct mount directory:

$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda     252:0    0   40G  0 disk 
├─vda1  252:1    0 39.9G  0 part /
├─vda14 252:14   0    4M  0 part 
└─vda15 252:15   0  106M  0 part /boot/efi
vdb     252:16   0   100G  0 disk  /mnt

Now, you can read and write into the new volume by writing to /mnt.

You can also optionally edit the "fstab" file (this is good to do). This ensures that the volume is still usable after rebooting the VM. The VM will read this file upon boot and do the mounting of the disk into the specified directory. For example, you can add the device at the last line (don't change the other lines in the file, such as the ones beginning with "LABEL"). As you can see, the last line will tell the VM to mount the disk named "vdb" to be accessible via "/mnt".

Remember that your volume may not have the name /dev/vdb. It could have the name /dev/vdc, or some other name.


$ cat /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
LABEL=UEFI      /boot/efi       vfat    defaults        0 0
/dev/vdb /mnt ext4 defaults,noatime 0 0


Doing mounting, formatting, etc. can destroy existing data if you're not careful, so practice doing the operations on a brand new VM and volume that you can throw away. The most important step is ensuring that you specify the correct device name, and that when you run mkfs, you realize that any data that exist on the volume will be erased.

Reference: https://www.digitalocean.com/community/tutorials/how-to-partition-and-format-storage-devices-in-linux

Detaching a volume from an instance

  1. Log in to the dashboard.
  2. Select the appropriate project from the drop down menu at the top left.
  3. On the Project tab, open the Volumes tab and click the Volumes category.
  4. Select the volume and click Manage Attachments.
  5. Click Detach Volume and confirm your changes.

A message indicates whether the action was successful.

Creating a snapshot from a volume

  1. Log in to the dashboard.

  2. Select the appropriate project from the drop down menu at the top left.

  3. On the Project tab, open the Volumes tab and click Volumes category.

  4. Select a volume from which to create a snapshot.

  5. In the Actions column, click Create Snapshot.

  6. In the dialog box that opens, enter a snapshot name and a brief description.

  7. Confirm your changes.

    The dashboard shows the new volume snapshot in Volume Snapshots tab.

Editing a volume

  1. Log in to the dashboard.

  2. Select the appropriate project from the drop down menu at the top left.

  3. On the Project tab, open the Volumes tab and click Volumes category.

  4. Select the volume that you want to edit.

  5. In the Actions column, click Edit Volume.

  6. In the Edit Volume dialog box, update the name and description of the volume.

  7. Click Edit Volume.
     

    Note

    You can extend a volume by using the Extend Volume option available in the More dropdown list and entering the new value for volume size.

Deleting a volume

When you delete an instance, the data in its attached volumes is not deleted.

  1. Log in to the dashboard.

  2. Select the appropriate project from the drop down menu at the top left.

  3. On the Project tab, open the Volumes tab and click Volumes category.

  4. Select the check boxes for the volumes that you want to delete.

  5. Click Delete Volumes and confirm your choice.

    A message indicates whether the action was successful.

Center for Computational Sciences