Skip to content

TUTORIAL: Block Storage With OpenStack

vlj91 edited this page Sep 30, 2015 · 4 revisions

#Using Block Storage with OpenStack One of the storage types we can use with our OpenStack compute instances is block storage.

Typical use cases for a block storage volume include:

  • Temporary persistent storage for data sets pulled from Object Stores or external reference data
  • Store non-disposable working data through instance termination
  • Block storageolumes can be used as a boot volume in the scenario ephemeral disk is not required

When a block storage volume should be used:

  • When reference and output data will not fit on local ephemeral Nova disk
  • As a temporary scratch filesystem prior to long-term data store
  • High changing content, large I/O

Disadvantages to block storage volumes:

  • No protection against accidental deletion
  • Typically less resiliency, try not to use for long-term storage
  • Difficult to manage Volumes
    • Cannot see what is inside a Volume without mounting

The following guide will detail some of the methods and options available for creating and attaching block storage volumes to an OpenStack compute instance.

##Prerequisites

  1. OpenStack Environment Access
  2. OpenStack User Networking Setup
  3. Launching OpenStack Instances

##Creating Block Storage Volumes ### Creating Volumes via CLI To begin creating a block storage volume using the OpenStack cinder module, log in to the cluster router node and ensure appropriate authentication.

$ SIZE=1000 #replace with the required size in GB
$ cinder create --display-name researchdata1 \
--display-description "Data for project X" \
$SIZE
$ CINDERVOL=<uniqueID>

Note down the Cinder volume unique ID or export the ID as a variable as above for later use. Verify successful creation of the new Cinder volume using the cinder list command.

### Creating Volumes via Horizon To begin creating a Cinder volume, log in to the Horizon GUI associated with your OpenStack environment and navigate to the Compute -> Volumes tab and click "Create Volume"

To create a simple Cinder volume, we recommend the following default settings:

Field Recommended setting
Volume Name Specify an identifiable name for the volume e.g. researchdata1
Description Provide a brief description of the proposed contents or its purpose
Volume Source No source, empty volume
Type No volume type
Size Specify size in GB
Availability zone Any availability zone

##Attaching Volumes With an instance successfully launched - we can begin attaching our new Cinder volume and begin using.

Cinder volumes can be manually attached and prepared for an instance, or attached to an instance on boot, and prepared either manually or automatically through cloud-init.

Cinder volumes can only be attached two one instance at any time.

###Manually Attaching Volumes #### Attaching Volumes via CLI To attach our new Cinder volume to our previously created instance, we will need both the Cinder volume unique ID (previously saved as $CINDERVOL, as well as our Nova instance unique ID or name). We will also need to provide a device ID e.g. /dev/vdb, or alternatively allow the Nova service to automatically assign a device ID with the auto tag. We reccomend using the auto device ID setting to avoid any potential clashes or errors.

To attach our Cinder volume to our instance:

$ nova volume-attach compute-vm $CINDERVOL auto

#### Attaching Volumes via Horizon To attach our new Cinder volume to our previously created instance via Horizon, log in to the Horizon GUI then navigate to the Compute -> Volumes tab - then using the drop down box on your Cinder volume, click the Edit Attachments button.

The Volume manager will provide a list of available instances to attach your Volume to. Once you have chosen the desired instance - click Attach Volume, a device ID will be automatically assigned:

##Preparing Volumes Preparation of the attached Cinder volume for use within the instance is performed via command-line. Log in to the Nova instance with the Cinder volume attached to a user with sudo rights.

When attaching the volume to our instance, we were either automatically assigned a device ID or manually set, e.g. /dev/vdb. To check the instance has the volume correctly, attached - run:

$ fdisk -l

We can see our 1TB Cinder volume:

Disk /dev/vdb: 1073.7 GB, 1073741824000 bytes, 2097152000 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

A new Cinder volume will need to have a filesystem created on the volume, using the mkfs command as a privileged user. We will use the ext4 filesystem:

$ mkfs.ext4 /dev/vdb

We will now need to create a directory on our instance to mount the Cinder volume to. This can be done automatically on boot via cloud-init, or in this case manually:

$ mkdir /mnt/researchdata1

Now mount the Cinder volume to our newly created directory:

$ mount /dev/vdb /mnt/researchdata1

Verify our Cinder volume has been successfully mounted:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  807M   20G   4% /
devtmpfs        984M     0  984M   0% /dev
tmpfs          1001M     0 1001M   0% /dev/shm
tmpfs          1001M   17M  985M   2% /run
tmpfs          1001M     0 1001M   0% /sys/fs/cgroup
/dev/vdb        985G   77M  935G   1% /mnt/researchdata1

We can now create temporary files and interact with our volume:

$ echo "File1" > /mnt/researchdata1/file1.txt 
$ echo "File2" > /mnt/researchdata1/file2.txt
$ mkdir /mnt/researchdata1/test
$ ls /mnt/researchdata1
file1.txt  file2.txt

##Reusing Volumes Similar to an external disk or USB drive, we can "unplug" our Cinder volumes once we are finished and reattatch them to a new instance, with the data still in tact. A Cinder volume can be detached from a live instance, or will be automatically detached on termination.

We can then attach our volume to any instance, or leave it in the Cinder store for later use. Once a Cinder volume has been prepared, we simply need to create a directory in our instance and mount the external volume each time.

### Detaching Volumes via CLI To detach a Cinder volume via Command line, we will need our Cinder volume ID (previously saved as the $CINDERVOL variable), and our Nova instance ID or name (e.g. compute-vm).

$ nova volume-detach compute-vm $CINDERVOL

Note: The nova volume-detach command provides no output - verify successful detatchment with the cinder list command.

### Detaching Volumes via Horizon To detach a Cinder volume from an instance via Horizon, navigate to the Compute -> Volumes tab. We can then use the dropdown menu on our Cinder volume to enter the Edit Attachments pane:

##Further reading The above examples are a demonstration of some of the many functions available within the OpenStack Cinder project. For additional features and tips, refer to the available OpenStack Cinder documentation

Clone this wiki locally