Now that we have a usable volume, we can attach it to any instance. We'll do this using the openstack server volume add
command.
To attach a volume to an instance, you will need the following:
openstack
command-line clientopenrc
file with appropriate credentials for the environmentFor our example, these values are as follows:
cookbook.volume
cookbook.test
Carry out the following steps to attach a volume to an instance using the openstack
client:
openstack server list -c Name -c ID -f table
An example showing our running instance called cookbook.test
is shown here:
openstack volume list
This shows the information we need about our volume:
openstack server add volume cookbook.test cookbook.volume --device /dev/vdc
This command produces no output when successful.
Note that the --device
option is not always honored, depending on the operating system and image type. Always check which device the target instance operating system assigns to the new volume before performing any actions on it.
Tip: Volume or server names do not have to be unique in OpenStack; where volume and server names are not unique, replace the names with the IDs assigned instead. In the preceding example, this would achieve the same goal:
openstack server add volume 90654098-477f-417f-b102-453c0f1f9119 daeddd6c-908a-4ea8-8632-d93d198c2621 --device /dev/vdb
lsblk
This will list the block devices available to our instance. Here we can see that our volume, attached as /dev/vdb
, is available but not mounted:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 558K 0 rom vda 253:0 0 2.2G 0 disk `-vda1 253:1 0 2.2G 0 part / vdb 253:16 0 10G 0 disk
10G
of space available for use by the running instance. As this is a new volume, this is like adding a fresh disk to a system. We need to format it for use and then mount it as part of your filesystem:sudo mkfs.ext4 /dev/vdb sudo mkdir /mnt1 sudo mount /dev/vdb /mnt1
/mnt1
:df -h
This will show output like the following:
Filesystem Size Used Avail Use% Mounted on udev 238M 0 238M 0% /dev tmpfs 49M 1.8M 48M 4% /run /dev/vda1 2.1G 843M 1.3G 41% / tmpfs 245M 0 245M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 245M 0 245M 0% /sys/fs/cgroup tmpfs 49M 0 49M 0% /run/user/1000 /dev/vdb 9.8G 23M 9.2G 1% /mnt1
Attaching a new Cinder volume is very much like plugging in an unformatted USB stick into your own computer. When it needs to first be used, it must be formatted for use.
Under the openstack
client, the server add volume
option takes the following syntax:
openstack server add volume instance_ID volume_ID --device /dev/device_ID
instance_ID
is the ID returned from openstack server list
for the instance that we want to attach the volume to.
volume_ID
is the ID of the volume returned from openstack volume list
.
device_ID
is the device that will be created on our instance that we use to mount the volume. Remember that this parameter can sometimes be ignored; so, see this as a hint to pass to a running instance only.
18.191.189.129