Attaching Block Storage

You can attach block storage to instances from the dashboard on the Volumes page. Click the Edit Attachments action next to the volume you want to attach.

To perform this action from command line, run the following command:

$ nova volume-attach <server> <volume> <device>

You can also specify block device mapping at instance boot time through the nova command-line client with this option set:

--block-device-mapping <dev-name=mapping> 

The block device mapping format is <dev-name>=<id>:<type>:<size(GB)>:<delete-on-terminate>, where:

dev-name

A device name where the volume is attached in the system at /dev/dev_name .

id

The ID of the volume to boot from, as shown in the output of nova volume-list.

type

Either snap, which means that the volume was created from a snapshot, or anything other than snap (a blank string is valid). In the example above, the volume was not created from a snapshot, so we leave this field blank in our example below.

size (GB)

The size of the volume in gigabytes. It is safe to leave this blank and have the Compute Service infer the size.

delete-on-terminate

A boolean to indicate whether the volume should be deleted when the instance is terminated. True can be specified as True or 1. False can be specified as False or 0.

The following command will boot a new instance and attach a volume at the same time. The volume of ID 13 will be attached as /dev/vdc. It is not a snapshot, does not specify a size, and will not be deleted when the instance is terminated:

$ nova boot --image 4042220e-4f5e-4398-9054-39fbd75a5dd7
            --flavor 2 --key-name mykey --block-device-mapping vdc=13:::0 boot-with-vol-test

If you have previously prepared block storage with a bootable file system image, it is even possible to boot from persistent block storage. The following command boots an image from the specified volume. It is similar to the previous command, but the image is omitted and the volume is now attached as /dev/vda:

$ nova boot --flavor 2 --key-name mykey
            --block-device-mapping vda=13:::0 boot-from-vol-test

Read more detailed instructions for launching an instance from a bootable volume in the OpenStack End User Guide.

To boot normally from an image and attach block storage, map to a device other than vda. You can find instructions for launching an instance and attaching a volume to the instance and for copying the image to the attached volume in the OpenStack End User Guide.

Questions? Discuss on ask.openstack.org
Found an error? Report a bug against this page

loading table of contents...