Persistent volumes, as the name says, stay even when instances are removed. They can be attached to or detached from virtual machines while they are running.
4.2.1 Creating and attaching volumes with the Pouta web interface
Persistent volumes can be created using either the web interface or through the command line interface.
In the web interface, use the Create volume button on the Volumes page to create a new volume. You may then give a name and a size for the volume (1GB is the minimum). The only mandatory argument is the size of the volume.
Once the volume has been created, it can be attached to a running virtual machine. One volume can be attached to only one virtual machine at a time.
To attach a volume, select first the Volumes view in the Pouta web interface. Click the arrow symbol next to the Edit Volume button for the volume you want to attach and select Manage attachments. Select the instance (i.e. virtual machine) you want to attach the volume to in the Attach To Instance selector.
4.2.2 Using attached volumes
The first time you use a attached volume it needs to be initialized. This should ONLY be done the FIRST time you use it, otherwise you overwrite all your data on the volume. First determine which device is your volume.
The following gives a simple usage example for creating a partition on the volume, creating a filesystem on the partition, mounting the filesystem and making the filesystem mount after a reboot. Note that this simple example is just one way to use the volumes. You can also use e.g. LVM or some other method of preparing the disk for use just as you would prepare a regular block device for use on a physical server.
Once you have logged into your virtual machine, you can list the volumes with:
sudo parted -l
You should be able to identify the volume based on its size. For this exercise, let's say that it is /dev/vdc. First you need to create a partition:
sudo parted -a optimal /dev/vdc mklabel gpt sudo parted -a optimal /dev/vdc mkpart primary 0% 100%
Next create a file system on it. We recommend ext4 or xfs for performance reasons:
sudo mkfs.ext4 /dev/vdc1
You should also create a label for the partition (limited to 16 characters):
sudo e2label /dev/vdc1 my-volume
Now you can start using it. For example, to mount it under /media/volume run:
sudo mount /dev/vdc1 /media/volume
Remember to unmount the volume before detaching it!
sudo umount /dev/vdc1
If you want the volume to be available after rebooting the virtual machine, you will need to add it to the /etc/fstab configuration file. You can use the label that you previously created for the partition:
sudo echo "LABEL=my-volume /media/volume ext4 defaults 0 0" >> /etc/fstab
After you attach the volume to another machine, you only need to run:
mkdir -p /media/volume mount /dev/vdc1 /media/volume
4.2.3 Creating and attaching volumes with command line tools
Persistent volumes can also be created and attached using the command line tools. The volume creation command is:
openstack volume create --description "<description>" --size <size> <name>
You can list existing volumes with the following command:
openstack volume list
You can list existing virtual machines to find the one to which you want to attach a volume to:
openstack server list
When a volume's status is "available", you can attach it to a virtual machine (you can use either names or ids to refer to the VM and the volume):
openstack server add volume <virtual machine> <volume>
A volume can only be attached to one virtual machine at a time.
When you no longer need the volume to be attached, you can detach it. Before detaching, remember to unmount the volume's filesystem on the virtual machine to avoid data loss! The detach volume command is as follows:
openstack server remove volume <server> <volume>
|Previous chapter||One level up||Next chapter|