Atom feed of this document
 

 Managing Volumes

Nova-volume is the service that allows you to give extra block level storage to your OpenStack Compute instances. You may recognize this as a similar offering from Amazon EC2 known as Elastic Block Storage (EBS). However, nova-volume is not the same implementation that EC2 uses today. Nova-volume is an iSCSI solution that employs the use of Logical Volume Manager (LVM) for Linux. Note that a volume may only be attached to one instance at a time. This is not a ‘shared storage’ solution like a SAN of NFS on which multiple servers can attach to.

Before going any further; let's discuss the nova-volume implementation in OpenStack:

The nova-volumes service uses iSCSI-exposed LVM volumes to the compute nodes which run instances. Thus, there are two components involved:

  1. lvm2, which works with a VG called "nova-volumes" (Refer to http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux) for further details)

  2. open-iscsi, the iSCSI implementation which manages iSCSI sessions on the compute nodes

Here is what happens from the volume creation to its attachment:

  1. The volume is created via nova volume-create; which creates an LV into the volume group (VG) "nova-volumes"

  2. The volume is attached to an instance via nova volume-attach; which creates a unique iSCSI IQN that will be exposed to the compute node

  3. The compute node which run the concerned instance has now an active ISCSI session; and a new local storage (usually a /dev/sdX disk)

  4. libvirt uses that local storage as a storage for the instance; the instance get a new disk (usually a /dev/vdX disk)

For this particular walkthrough, there is one cloud controller running nova-api, nova-scheduler, nova-objectstore, nova-network and nova-volume services. There are two additional compute nodes running nova-compute. The walkthrough uses a custom partitioning scheme that carves out 60GB of space and labels it as LVM. The network is a /28 .80-.95, and FlatManger is the NetworkManager setting for OpenStack Compute (Nova).

Please note that the network mode doesn't interfere at all with the way nova-volume works, but networking must be set up for for nova-volumes to work. Please refer to Networking for more details.

To set up Compute to use volumes, ensure that nova-volume is installed along with lvm2. The guide will be split in four parts :

  • A- Installing the nova-volume service on the cloud controller.

  • B- Configuring the "nova-volumes" volume group on the compute nodes.

  • C- Troubleshooting your nova-volume installation.

  • D- Backup your nova volumes.

 A- Install nova-volume on the cloud controller.

This is simply done by installing the two components on the cloud controller :

$ apt-get install lvm2 nova-volume
            

  • Configure Volumes for use with nova-volume

    If you do not already have LVM volumes on hand, but have free drive space, you will need to create a LVM volume before proceeding. Here is a short run down of how you would create a LVM from free drive space on your system. Start off by issuing an fdisk command to your drive with the free space:

    $ fdisk /dev/sda
                                

    Once in fdisk, perform the following commands:

    1. Press n to create a new disk partition,

    2. Press p to create a primary disk partition,

    3. Press 1 to denote it as 1st disk partition,

    4. Either press ENTER twice to accept the default of 1st and last cylinder – to convert the remainder of hard disk to a single disk partition -OR- press ENTER once to accept the default of the 1st, and then choose how big you want the partition to be by specifying +size[K,M,G] e.g. +5G or +6700M.

    5. Press t and select the new partition that you have created.

    6. Press 8e change your new partition to 8e, i.e. Linux LVM partition type.

    7. Press p to display the hard disk partition setup. Please take note that the first partition is denoted as /dev/sda1 in Linux.

    8. Press w to write the partition table and exit fdisk upon completion.

      Refresh your partition table to ensure your new partition shows up, and verify with fdisk. We then inform the OS about the table partition update :

      $ partprobe
      $ fdisk -l
                                               

      You should see your new partition in this listing.

      Here is how you can set up partitioning during the OS install to prepare for this nova-volume configuration:

      root@osdemo03:~# fdisk -l
                                          

      Device Boot Start End Blocks Id System
      
      /dev/sda1 * 1 12158 97280 83 Linux
      /dev/sda2 12158 24316 97655808 83 Linux
      
      /dev/sda3 24316 24328 97654784 83 Linux
      /dev/sda4 24328 42443 145507329 5 Extended
      
      /dev/sda5 24328 32352 64452608 8e Linux LVM
      /dev/sda6 32352 40497 65428480 8e Linux LVM
      
      /dev/sda7 40498 42443 15624192 82 Linux swap / Solaris
      

      Now that you have identified a partition has been labeled for LVM use, perform the following steps to configure LVM and prepare it as nova-volumes. You must name your volume group ‘nova-volumes’ or things will not work as expected:

      $ pvcreate /dev/sda5
      $ vgcreate nova-volumes /dev/sda5
                                          

 B- Configuring nova-volume on the compute nodes

Since you have created the volume group, you will be able to use the following tools for managing your volumes:

nova volume-create

nova volume-attach

nova volume-detach

nova volume-delete

[Note]Note

If you are using KVM as your hypervisor, then the actual device name in the guest will be different than the one specified in the nova volume-attach command. You can specify a device name to the KVM hypervisor, but the actual means of attaching to the guest is over a virtual PCI bus. When the guest sees a new device on the PCI bus, it picks the next available name (which in most cases is /dev/vdc) and the disk shows up there on the guest.

  • Installing and configuring the iSCSI initiator

    Remember that every node will act as the iSCSI initiator while the server running nova-volumes will act as the iSCSI target. So make sure, before going further that your nodes can communicate with you nova-volumes server. If you have a firewall running on it, make sure that the port 3260 (tcp) accepts incoming connections.

    First install the open-iscsi package on the initiators, so on the compute-nodes only

    $ apt-get install open-iscsi
                        

    Then on the target, which is in our case the cloud-controller, the iscsitarget package :

    $ apt-get install iscsitarget
                            

    This package could refuse to start with a "FATAL: Module iscsi_trgt not found" error.

    This error is caused by the kernel which does not contain the iscsi module's source into it ; you can install the kernel modules by installing an extra package :

    $ apt-get install iscsitarget-dkms
                            

    (the Dynamic Kernel Module Support is a framework used for created modules with non-existent sources into the current kernel)

    You have to enable it so the startut script (/etc/init.d/iscsitarget) can start the daemon:

    $ sed -i 's/false/true/g' /etc/default/iscsitarget
                            

    Then run on the nova-controller (iscsi target) :

    $ service iscsitarget start
                                

    And on the compute-nodes (iscsi initiators) :

    $ service open-iscsi start
                                
  • Start nova-volume and create volumes

    You are now ready to fire up nova-volume, and start creating volumes!

    $ service nova-volume start

    Once the service is started, login to your controller and ensure you’ve properly sourced your ‘novarc’ file.

    One of the first things you should do is make sure that nova-volume is checking in as expected. You can do so using nova-manage:

    $ nova-manage service list
                            

    If you see a smiling ‘nova-volume’ in there, you are looking good. Now create a new volume:

    $ nova volume-create --display_name myvolume 10
                            

    --display_name sets a readable name for the volume, while the final argument refers to the size of the volume in GB.

    You should get some output similar to this:

                            +----+-----------+--------------+------+-------------+--------------------------------------+
                            | ID |   Status  | Display Name | Size | Volume Type |             Attached to              |
                            +----+-----------+--------------+------+-------------+--------------------------------------+
                            | 1  | available | myvolume     | 10   | None        |                                      |
                            +----+-----------+--------------+------+-------------+--------------------------------------+
                            

    You can view that status of the volumes creation using nova volume-list. Once that status is ‘available,’ it is ready to be attached to an instance:

    $ nova volume-attach 857d70e4-35d5-4bf6-97ed-bf4e9a4dcf5a 1 /dev/vdb
                        

    The first argument refers to the instance you will attach the volume to; The second is the volume ID; The third is the mountpoint on the compute-node that the volume will be attached to

    By doing that, the compute-node which runs the instance basically performs an iSCSI connection and creates a session. You can ensure that the session has been created by running :

    $ iscsiadm -m session
                        

    Which should output :

    root@nova-cn1:~# iscsiadm -m session
    tcp: [1] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-1

    If you do not get any errors, you can login to the instance and see if the new space is there.

    KVM changes the device name, since it's not considered to be the same type of device as the instances uses as it's local one, you will find the nova-volume will be designated as "/dev/vdX" devices, while local are named "/dev/sdX".

    You can check the volume attachment by running :

    $ dmesg | tail
                        

    You should from there see a new disk. Here is the output from fdisk -l:

    Disk /dev/vda: 10.7 GB, 10737418240 bytes
    16 heads, 63 sectors/track, 20805 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0×00000000
    Disk /dev/vda doesn’t contain a valid partition table
    Disk /dev/vdb: 21.5 GB, 21474836480 bytes <—–Here is our new volume!
    16 heads, 63 sectors/track, 41610 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0×00000000
                        

    Now with the space presented, let’s configure it for use:

    $ fdisk /dev/vdb
                            

    1. Press n to create a new disk partition.

    2. Press p to create a primary disk partition.

    3. Press 1 to designated it as the first disk partition.

    4. Press ENTER twice to accept the default of first and last cylinder – to convert the remainder of hard disk to a single disk partition.

    5. Press t, then select the new partition you made.

    6. Press 83 change your new partition to 83, i.e. Linux partition type.

    7. Press p to display the hard disk partition setup. Please take note that the first partition is denoted as /dev/vda1 in your instance.

    8. Press w to write the partition table and exit fdisk upon completion.

    9. Lastly, make a file system on the partition and mount it.

      $ mkfs.ext3 /dev/vdb1
      $ mkdir /extraspace
      $ mount /dev/vdb1 /extraspace
                                      

    Your new volume has now been successfully mounted, and is ready for use! The commands are pretty self-explanatory, so play around with them and create new volumes, tear them down, attach and reattach, and so on.

 C- Troubleshoot your nova-volume installation

If the volume attachment doesn't work, you should be able to perform different checks in order to see where the issue is. The nova-volume.log and nova-compute.log will help you to diagnosis the errors you could encounter :

nova-compute.log / nova-volume.log

  • ERROR "Cannot resolve host"

    (nova.root): TRACE: ProcessExecutionError: Unexpected error while running command.
    (nova.root): TRACE: Command: sudo iscsiadm -m discovery -t sendtargets -p ubuntu03c
    (nova.root): TRACE: Exit code: 255
    (nova.root): TRACE: Stdout: ''
    (nova.root): TRACE: Stderr: 'iscsiadm: Cannot resolve host ubuntu03c. getaddrinfo error: [Name or service not known]\n\niscsiadm:
    cannot resolve host name ubuntu03c\niscsiadm: Could not perform SendTargets discovery.\n'
    (nova.root): TRACE:
                                

    This error happens when the compute node is unable to resolve the nova-volume server name. You could either add a record for the server if you have a DNS server; or add it into the /etc/hosts file of the nova-compute.

  • ERROR "No route to host"

    iscsiadm: cannot make connection to 172.29.200.37: No route to host\niscsiadm: cannot make connection to 172.29.200.37
                                

    This error could be caused by several things, but it means only one thing : openiscsi is unable to establish a communication with your nova-volumes server.

    The first thing you could do is running a telnet session in order to see if you are able to reach the nova-volume server. From the compute-node, run :

    $ telnet $ip_of_nova_volumes  3260
                            

    If the session times out, check the server firewall ; or try to ping it. You could also run a tcpdump session which may also provide extra information :

    $ tcpdump -nvv -i $iscsi_interface port dest $ip_of_nova_volumes
                            

    Again, try to manually run an iSCSI discovery via :

    $ iscsiadm -m discovery -t st -p $ip_of_nova-volumes
                            
  • "Lost connectivity between nova-volumes and node-compute ; how to restore a clean state ?"

    Network disconnection can happens, from an "iSCSI view", losing connectivity could be seen as a physical removal of a server's disk. If the instance runs a volume while you loose the network between them, you won't be able to detach the volume. You would encounter several errors. Here is how you could clean this :

    First, from the nova-compute, close the active (but stalled) iSCSI session, refer to the volume attached to get the session, and perform the following command :

    $ iscsiadm -m session -r $session_id -u
                            

    Here is an iscsi -m session output :

    tcp: [1] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-1
    tcp: [2] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-2
    tcp: [3] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-3
    tcp: [4] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-4
    tcp: [5] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-5
    tcp: [6] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-6
    tcp: [7] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-7
    tcp: [9] 172.16.40.244:3260,1 iqn.2010-10.org.openstack:volume-9
                            

    For example, to free volume 9, close the session number 9.

    The cloud-controller is actually unaware of the iSCSI session closing, and will keeps the volume state as in-use:

                                +----+-----------+--------------+------+-------------+--------------------------------------+
                                | ID |   Status  | Display Name | Size | Volume Type |             Attached to              |
                                +----+-----------+--------------+------+-------------+--------------------------------------+
                                | 9  | in-use    | New Volume   | 20   | None        | 7db4cb64-7f8f-42e3-9f58-e59c9a31827d |
                                

    You now have to inform the cloud-controller that the disk can be used. Nova stores the volumes info into the "volumes" table. You will have to update four fields into the database nova uses (eg. MySQL). First, conect to the database :

    $ mysql -uroot -p$password nova
                            

    Using the volume id, you will have to run the following sql queries

    mysql> update volumes set mountpoint=NULL where id=9;
    mysql> update volumes set status="available" where status "error_deleting" where id=9;
    mysql> update volumes set attach_status="detached" where id=9;
    mysql> update volumes set instance_id=0 where id=9;
                            

    Now if you run again nova volume-list from the cloud controller, you should see an available volume now :

                                +----+-----------+--------------+------+-------------+--------------------------------------+
                                | ID |   Status  | Display Name | Size | Volume Type |             Attached to              |
                                +----+-----------+--------------+------+-------------+--------------------------------------+
                                | 9  | available  | New Volume   | 20   | None       |                                      |
                            

    You can now proceed to the volume attachment again!

 D- Backup your nova-volume disks

While Diablo provides the snapshot functionality (using LVM snapshot), you can also back up your volumes. The advantage of this method is that it reduces the size of the backup; only existing data will be backed up, instead of the entire volume. For this example, assume that a 100 GB nova-volume has been created for an instance, while only 4 gigabytes are used. This process will back up only those 4 giga-bytes, with the following tools:

  1. lvm2, directly manipulates the volumes.

  2. kpartx discovers the partition table created inside the instance.

  3. tar creates a minimum-sized backup

  4. sha1sum calculates the backup checksum, to check its consistency

1- Create a snapshot of a used volume

  • In order to backup our volume, we first need to create a snapshot of it. An LVM snapshot is the exact copy of a logical volume, which contains data in a frozen state. This prevents data corruption, because data will not be manipulated during the process of creating the volume itself. Remember the volumes created through a nova volume-create exist in an LVM's logical volume.

    Before creating the snapshot, ensure that you have enough space to save it. As a precaution, you should have at least twice as much space as the potential snapshot size. If insufficient space is available, there is a risk that the snapshot could become corrupted.

    Use the following command to obtain a list of all volumes.

    $ lvdisplay
                            

    In this example, we will refer to a volume called volume-00000001, which is a 10GB volume. This process can be applied to all volumes, not matter their size. At the end of the section, we will present a script that you could use to create scheduled backups. The script itself exploits what we discuss here.

    First, create the snapshot; this can be achieved while the volume is attached to an instance :

    $ lvcreate --size 10G --snapshot --name volume-00000001-snapshot /dev/nova-volumes/volume-00000001
                            

    We indicate to LVM we want a snapshot of an already existing volume with the --snapshot configuration option. The command includes the size of the space reserved for the snapshot volume, the name of the snapshot, and the path of an already existing volume (In most cases, the path will be /dev/nova-volumes/$volume_name).

    The size doesn't have to be the same as the volume of the snapshot. The size parameter designates the space that LVM will reserve for the snapshot volume. As a precaution, the size should be the same as that of the original volume, even if we know the whole space is not currently used by the snapshot.

    We now have a full snapshot, and it only took few seconds !

    Run lvdisplay again to verify the snapshot. You should see now your snapshot :

                      --- Logical volume ---
      LV Name                /dev/nova-volumes/volume-00000001
      VG Name                nova-volumes
      LV UUID                gI8hta-p21U-IW2q-hRN1-nTzN-UC2G-dKbdKr
      LV Write Access        read/write
      LV snapshot status     source of
                             /dev/nova-volumes/volume-00000026-snap [active]
      LV Status              available
      # open                 1
      LV Size                15,00 GiB
      Current LE             3840
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           251:13
    
      --- Logical volume ---
      LV Name                /dev/nova-volumes/volume-00000001-snap
      VG Name                nova-volumes
      LV UUID                HlW3Ep-g5I8-KGQb-IRvi-IRYU-lIKe-wE9zYr
      LV Write Access        read/write
      LV snapshot status     active destination for /dev/nova-volumes/volume-00000026
      LV Status              available
      # open                 0
      LV Size                15,00 GiB
      Current LE             3840
      COW-table size         10,00 GiB
      COW-table LE           2560
      Allocated to snapshot  0,00%
      Snapshot chunk size    4,00 KiB
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           251:14
                

2- Partition table discovery

  • If we want to exploit that snapshot with the tar program, we first need to mount our partition on the nova-volumes server.

    kpartx is a small utility which performs table partition discoveries, and maps it. It can be used to view partitions created inside the instance. Without using the partitions created inside instances, we won' t be able to see its content and create efficient backups.

    $ kpartx -av /dev/nova-volumes/volume-00000001-snapshot
                            

    If no errors are displayed, it means the tools has been able to find it, and map the partition table. Note that on a Debian flavor distro, you could also use apt-get install kpartx.

    You can easily check the partition table map by running the following command:

    $ ls /dev/mapper/nova*
                        

    You should now see a partition called nova--volumes-volume--00000001--snapshot1

    If you created more than one partition on that volumes, you should have accordingly several partitions; for example. nova--volumes-volume--00000001--snapshot2, nova--volumes-volume--00000001--snapshot3 and so forth.

    We can now mount our partition :

    $ mount /dev/mapper/nova--volumes-volume--volume--00000001--snapshot1 /mnt
                            

    If there are no errors, you have successfully mounted the partition.

    You should now be able to directly access the data that were created inside the instance. If you receive a message asking you to specify a partition, or if you are unable to mount it (despite a well-specified filesystem) there could be two causes :

    • You didn't allocate enough space for the snapshot

    • kpartx was unable to discover the partition table.

    Allocate more space to the snapshot and try the process again.

3- Use tar in order to create archives

  • Now that the volume has been mounted, you can create a backup of it :

    $ tar --exclude={"lost+found","some/data/to/exclude"} -czf volume-00000001.tar.gz -C /mnt/ /backup/destination
                                

    This command will create a tar.gz file containing the data, and data only. This ensures that you do not waste space by backing up empty sectors.

4- Checksum calculation I

  • You should always have the checksum for your backup files. The checksum is a unique identifier for a file.

    When you transfer that same file over the network, you can run another checksum calculation. If the checksums are different, this indicates that the file is corrupted; thus, the checksum provides a method to ensure your file has not been corrupted during its transfer.

    The following command runs a checksum for our file, and saves the result to a file :

    $ sha1sum volume-00000001.tar.gz > volume-00000001.checksum
                            

    Be aware the sha1sum should be used carefully, since the required time for the calculation is directly proportional to the file's size.

    For files larger than ~4-6 gigabytes, and depending on your CPU, the process may take a long time.

5- After work cleaning

  • Now that we have an efficient and consistent backup, the following commands will clean up the file system.

    1. Unmount the volume: unmount /mnt

    2. Delete the partition table: kpartx -dv /dev/nova-volumes/volume-00000001-snapshot

    3. Remove the snapshot: lvremove -f /dev/nova-volumes/volume-00000001-snapshot

    And voila :) You can now repeat these steps for every volume you have.

6- Automate your backups

Because you can expect that more and more volumes will be allocated to your nova-volume service, you may want to automate your backups. This script here will assist you on this task. The script performs the operations from the previous example, but also provides a mail report and runs the backup based on the backups_retention_days setting. It is meant to be launched from the server which runs the nova-volumes component.

Here is an example of a mail report:

Backup Start Time - 07/10 at 01:00:01
Current retention - 7 days

The backup volume is mounted. Proceed...
Removing old backups...  : /BACKUPS/EBS-VOL/volume-00000019/volume-00000019_28_09_2011.tar.gz
     /BACKUPS/EBS-VOL/volume-00000019 - 0 h 1 m and 21 seconds. Size - 3,5G

The backup volume is mounted. Proceed...
Removing old backups...  : /BACKUPS/EBS-VOL/volume-0000001a/volume-0000001a_28_09_2011.tar.gz
     /BACKUPS/EBS-VOL/volume-0000001a - 0 h 4 m and 15 seconds. Size - 6,9G
---------------------------------------
Total backups size - 267G - Used space : 35%
Total execution time - 1 h 75 m and 35 seconds
            

The script also provides the ability to SSH to your instances and run a mysqldump into them. In order to make this to work, ensure the connection via the nova's project keys is enabled. If you don't want to run the mysqldumps, you can turn off this functionality by adding enable_mysql_dump=0 to the script.



loading table of contents...