Chapter 18. Grouping LVM objects with tags

As a system administrator, you can assign tags to LVM objects to group them, so that you can automate the control of LVM behavior, such as activation, by group.

18.1. LVM object tags

An LVM tag is a word that is used to group LVM2 objects of the same type together. Tags are attached to objects such as physical volumes, volume groups, and logical volumes, as well as to hosts in a cluster configuration.

Tags are given on the command line in place of PV, VG or LV arguments. Tags should be prefixed with @ to avoid ambiguity. Each tag is expanded by replacing it with all objects possessing that tag which are of the type expected by its position on the command line.

LVM tags are strings of up to 1024 characters. LVM tags cannot start with a hyphen.

A valid tag consists of a limited range of characters only. The allowed characters are A-Z a-z 0-9 _ + . - / = ! : # &.

Only objects in a volume group can be tagged. Physical volumes lose their tags if they are removed from a volume group; this is because tags are stored as part of the volume group metadata and that is deleted when a physical volume is removed.

18.2. Listing LVM tags

The following example shows how to list LVM tags.

Procedure

  • Use the following command to list all the logical volumes with the database tag:
# lvs @database
  • Use the following command to list the currently active host tags:
# lvm tags

18.3. Adding LVM object tags

This procedure describes how to add LVM object tags.

Prerequisites

  • The lvm2 package is installed.
  • One or more physical volumes, volume groups, or logical volumes are created.

Procedure

  • To create an object tag, add the --addtag option to an LVM command:

    • To create tags from physical volumes, add the option to the pvchange command.
    • To create tags from volume groups, add the option to the vgchange or vgcreate commands.
    • To create tags from logical volumes, add the option to the lvchange or lvcreate commands.

18.4. Removing LVM object tags

This procedure describes how to remove LVM object tags.

Prerequisites

  • The lvm2 package is installed.
  • Object tags on physical volumes, volume groups, or logical volumes are created.

Procedure

  • To delete an object tag, add the --deltag option to an LVM command:

    • To delete tags from physical volumes, add the option to the pvchange command.
    • To delete tags from volume groups, add the option to the vgchange or vgcreate commands.
    • To delete tags from logical volumes, add the option to the lvchange or lvcreate commands.

18.5. Defining LVM host tags

This procedure describes how to define LVM host tags in a cluster configuration. You can define host tags in the configuration files.

Procedure

  • Set hosttags = 1 in the tags section to automatically define host tag using the machine’s host name.

    This allows you to use a common configuration file which can be replicated on all your machines so they hold identical copies of the file, but the behavior can differ between machines according to the host name.

For each host tag, an extra configuration file is read if it exists: lvm_hosttag.conf. If that file defines new tags, then further configuration files will be appended to the list of files to read in.

For example, the following entry in the configuration file always defines tag1, and defines tag2 if the host name is host1:

tags { tag1 { }  tag2 { host_list = ["host1"] } }

18.6. Controlling logical volume activation with tags

This procedure describes how to specify in the configuration file that only certain logical volumes should be activated on that host.

Prerequisites

  • A bulleted list of conditions that must be satisfied before the user starts following this assembly.
  • You can also link to other modules or assemblies the user must follow before starting this assembly.
  • Delete the section title and bullets if the assembly has no prerequisites.

Procedure

For example, the following entry acts as a filter for activation requests (such as vgchange -ay) and only activates vg1/lvol0 and any logical volumes or volume groups with the database tag in the metadata on that host:

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

The special match @* that causes a match only if any metadata tag matches any host tag on that machine.

As another example, consider a situation where every machine in the cluster has the following entry in the configuration file:

tags { hosttags = 1 }

If you want to activate vg1/lvol2 only on host db2, do the following:

  1. Run lvchange --addtag @db2 vg1/lvol2 from any host in the cluster.
  2. Run lvchange -ay vg1/lvol2.

This solution involves storing host names inside the volume group metadata.