4.7 Tagging LVM2 Storage Objects

A tag is an unordered keyword or term assigned to the metadata of a storage object. Tagging allows you to classify collections of LVM storage objects in ways that you find useful by attaching an unordered list of tags to their metadata.

4.7.1 Using LVM2 Tags

After you tag the LVM2 storage objects, you can use the tags in commands to accomplish the following tasks:

  • Select LVM objects for processing according to the presence or absence of specific tags.

  • Use tags in the configuration file to control which volume groups and logical volumes are activated on a server.

  • Override settings in a global configuration file by specifying tags in the command.

A tag can be used in place of any command line LVM object reference that accepts:

  • a list of objects

  • a single object as long as the tag expands to a single object

Replacing the object name with a tag is not supported everywhere yet. After the arguments are expanded, duplicate arguments in a list are resolved by removing the duplicate arguments, and retaining the first instance of each argument.

Wherever there might be ambiguity of argument type, you must prefix a tag with the commercial at sign (@) character, such as @mytag. Elsewhere, using the @ prefix is optional.

4.7.2 Requirements for Creating LVM2 Tags

Consider the following requirements when using tags with LVM:

Supported Characters

An LVM tag word can contain the ASCII uppercase characters A to Z, lowercase characters a to z, numbers 0 to 9, underscore (_), plus (+), hyphen (-), and period (.). The word cannot begin with a hyphen. The maximum length is 128 characters.

Supported Storage Objects

You can tag LVM2 physical volumes, volume groups, logical volumes, and logical volume segments. PV tags are stored in its volume group’s metadata. Deleting a volume group also deletes the tags in the orphaned physical volume. Snapshots cannot be tagged, but their origin can be tagged.

LVM1 objects cannot be tagged because the disk format does not support it.

4.7.3 Command Line Tag Syntax

--addtag <tag_info>

Add a tag to (or tag) an LVM2 storage object.

Example

vgchange --addtag @db1 vg1
--deltag <tag_info>

Remove a tag from (or untag) an LVM2 storage object.

Example

vgchange --deltag @db1 vg1
--tag <tag_info>

Specify the tag to use to narrow the list of volume groups or logical volumes to be activated or deactivated.

Example

Enter the following to activate it the volume if it has a tag that matches the tag provided:

lvchange -ay --tag @db1 vg1/vol2

4.7.4 Configuration File Syntax

Enabling Hostname Tags in the lvm.conf File

Add the following code to the /etc/lvm/lvm.conf file to enable host tags that are defined separately on host in a /etc/lvm/lvm_<hostname>.conf file.

tags {
   # Enable hostname tags
   hosttags = 1
}

You place the activation code in the /etc/lvm/lvm_<hostname>.conf file on the host. See Defining Activation.

Defining Tags for Hostnames in the lvm.conf File

tags {

   tag1 { }
      # Tag does not require a match to be set.

   tag2 {
      # If no exact match, tag is not set.
      host_list = [ "hostname1", "hostname2" ]
   }
}

Defining Activation

You can modify the /etc/lvm/lvm.conf file to activate LVM logical volumes based on tags.

In a text editor, add the following code to the file:

  activation {
      volume_list = [ "vg1/lvol0", "@database" ]
  }

Replace @database with the your tag. Use "@*" to match the tag against any tag set on the host.

The activation command matches against vgname, vgname/lvname, or @tag set in the metadata of volume groups and logical volumes. A volume group or logical volume is activated only if a metadata tag matches. The default if there is no match is not to activate.

If volume_list is not present and any tags are defined on the host, then it activates the volume group or logical volumes only if a host tag matches a metadata tag.

If volume_list is not present and no tags are defined on the host, then it does activate.

Defining Activation in Multiple Hostname Configuration Files

You can use the activation code in a host’s configuration file (/etc/lvm/lvm_<host_tag>.conf) when host tags are enabled in the lvm.conf file. For example, a server has two configuration files in the /etc/lvm/ folder:

  • lvm.conf
  • lvm_<host_tag>.conf

At startup, load the /etc/lvm/lvm.conf file, and process any tag settings in the file. If any host tags were defined, it loads the related /etc/lvm/lvm_<host_tag>.conf file.When it searches for a specific configuration file entry, it searches the host tag file first, then the lvm.conf file, and stops at the first match.Within the lvm_<host_tag>.conf file, use the reverse order that tags were set. This allows the file for the last tag set to be searched first. New tags set in the host tag file will trigger additional configuration file loads.

4.7.5 Using Tags for a Simple Activation Control in a Cluster

You can set up a simple hostname activation control by enabling the hostname_tags option in a the /etc/lvm/lvm.conf file. Use the same file on every machine in a cluster so that it is a global setting.

  1. In a text editor, add the following code to the /etc/lvm/lvm.conf file:

    tags {
       hostname_tags = 1
    }
    
  2. Replicate the file to all hosts in the cluster.

  3. From any machine in the cluster, add db1 to the list of machines that activate vg1/lvol2:

    lvchange --addtag @db1 vg1/lvol2
    
  4. On the db1 server, enter the following to activate it:

    lvchange -ay vg1/vol2
    

4.7.6 Using Tags to Activate On Preferred Hosts in a Cluster

The examples in this section demonstrate two methods to accomplish the following:

  • Activate volume group vg1 only on the database hosts db1 and db2.

  • Activate volume group vg2 only on the file server host fs1.

  • Activate nothing initially on the file server backup host fsb1, but be prepared for it to take over from the file server host fs1.

Option 1: Centralized Admin and Static Configuration Replicated Between Hosts

In the following solution, the single configuration file is replicated among multiple hosts.

  1. Add the @database tag to the metadata of volume group vg1. In a terminal console, enter

    vgchange --addtag @database vg1
    
  2. Add the @fileserver tag to the metadata of volume group vg2. In a terminal console, enter

    vgchange --addtag @fileserver vg2
    
  3. In a text editor, modify the /etc/lvm/lvm.conf file with the following code to define the @database, @fileserver, @fileserverbackup tags.

    tags {
       database {
          host_list = [ "db1", "db2" ]
       }
       fileserver {
          host_list = [ "fs1" ]
       }
       fileserverbackup {
          host_list = [ "fsb1" ]
       }
    }
    
    activation {
       # Activate only if host has a tag that matches a metadata tag
       volume_list = [ "@*" ]
    }
    
  4. Replicate the modified /etc/lvm/lvm.conf file to the four hosts: db1, db2, fs1, and fsb1.

  5. If the file server host goes down, vg2 can be brought up on fsb1 by entering the following commands in a terminal console on any node:

    vgchange --addtag @fileserverbackup vg2
    vgchange -ay vg2
    

Option 2: Localized Admin and Configuration

In the following solution, each host holds locally the information about which classes of volume to activate.

  1. Add the @database tag to the metadata of volume group vg1. In a terminal console, enter

    vgchange --addtag @database vg1
    
  2. Add the @fileserver tag to the metadata of volume group vg2. In a terminal console, enter

    vgchange --addtag @fileserver vg2
    
  3. Enable host tags in the /etc/lvm/lvm.conf file:

    1. In a text editor, modify the /etc/lvm/lvm.conf file with the following code to enable host tag configuration files.

      tags {
         hosttags = 1
      }
      
    2. Replicate the modified /etc/lvm/lvm.conf file to the four hosts: db1, db2, fs1, and fsb1.

  4. On host db1, create an activation configuration file for the database host db1. In a text editor, create a /etc/lvm/lvm_db1.conf file and add the following code:

    activation {
       volume_list = [ "@database" ]
    }
    
  5. On host db2, create an activation configuration file for the database host db2. In a text editor, create a /etc/lvm/lvm_db2.conf file and add the following code:

    activation {
       volume_list = [ "@database" ]
    }
    
  6. On host fs1, create an activation configuration file for the file server host fs1.In a text editor, create a /etc/lvm/lvm_fs1.conf file and add the following code:

    activation {
       volume_list = [ "@fileserver" ]
    }
    
  7. If the file server host fs1 goes down, to bring up a spare file server host fsb1 as a file server:

    1. On host fsb1, create an activation configuration file for the host fsb1. In a text editor, create a /etc/lvm/lvm_fsb1.conf file and add the following code:

      activation {
         volume_list = [ "@fileserver" ]
      }
      
    2. In a terminal console, enter one of the following commands:

      vgchange -ay vg2
      
      vgchange -ay @fileserver