Home / How to configure LVM filter settings in CentOS 5, 6, 7, 8?

How to configure LVM filter settings in CentOS 5, 6, 7, 8?

LVM how to

What is the LVM filter?

vgscan is launched during boot to examine the system’s disks and create a metadata map of the LVM partitions.

  • This information is kept in the file /etc/lvm/cache/.cache.
  • During this process, drives are evaluated depending on a filter defined in lvm.conf.
    This file is located in CentOS 6 and CentOS 7 at /etc/lvm/lvm.conf.

Perform the following three steps to switch from the default LVM filter to a more restrictive filter.

Simple Method Script

Based on the LVM devices discovered, the simple method script generates a suggested lvm filter. The script prefers /dev/disk/by-id links over /dev/sd* and /dev/nvme* names because they are not always persistent across reboot. Copy and paste the following into the terminal as shown:

filter="" ; while read -ra line; do
    if [[ "${line[1]}" = "lvm2" ]] && [[ -n "${line[2]}" ]]; then
        if [[ "${line[0]}" == "/dev/sd"* ]] || [[ "${line[0]}" == "/dev/nvme"* ]]; then
            while read -ra line2; do
                if [[ "${line[0]}" == "$(readlink -f $line2)" ]]; then
                    filter+=""a|$line2|", "
                    break
                fi
            done <<< "$(ls -U /dev/disk/by-id/{scsi-[23]*,scsi-*,nvme-*} 2>/dev/null)"
        else
            filter+=""a|${line[0]}|", "
        fi
        $(multipath -c ${line[0]} &>/dev/null)
        [[ $? -eq 0 ]] && printf "%s %sn" "Warning: ${line[0]} is a valid multipath device " 
                                 "path. Verify mappings and filter."
    fi
done <<< "$(pvs -a --config 'devices { global_filter = [ "a|.*|" ] filter = [ "a|.*|" ] }' 
    --noheadings -o pv_name,fmt,pv_uuid)" ; filter+=""r|.*|" ]" ; printf "%sn%sn%sn" 
    "Suggested filter lines for /etc/lvm/lvm.conf:" "filter = [ $filter" "global_filter = [ $filter"

Example output is given below:

Suggested filter lines for /etc/lvm/lvm.conf:
filter = [ "a|/dev/hda2|", "a|/dev/mapper/mpath0|", "a|/dev/mapper/mpath1|", "r|.*|" ]
global_filter = [ "a|/dev/hda2|", "a|/dev/mapper/mpath0|", "a|/dev/mapper/mpath1|", "r|.*|" ]

Adjust the Simple Method Filter

You might be able to combine devices and simplify the proposed filter, for example.

"a|/dev/mapper/mpath0|", "a|/dev/mapper/mpath1|"

This could be shortened to:

"a|/dev/mapper/mpath[01]|"

Based on anticipated future storage expansions, you may want to add or adjust the suggested filter.

Future storage increases will necessitate a change to the filter line if the filter is too restrictive.

Filtering on the specific device names from the ‘pvs’ list, for example, maybe overly limiting if you expect to add more /dev/mapper/mpath* devices in the future.
We’d create the following filter based on the output:

filter = [ "a|/dev/hda2|", "a|/dev/mapper/mpath|", "r|.*|" ]
global_filter = [ "a|/dev/hda2|", "a|/dev/mapper/mpath|", "r|.*|" ]

You can utilize it if you know the device’s SCSI ID. You can use: 36001405a0fade84962547bca5175f033 if your SCSI ID is 36001405a0fade84962547bca5175f033.

filter = [ "a|36001405a0fade84962547bca5175f033|", "a|/dev/mapper/mpath|", "r|.*|" ]
global_filter = [ "a|36001405a0fade84962547bca5175f033|", "a|/dev/mapper/mpath|", "r|.*|" ]

(The command /lib/udev/scsi id –whitelisted /dev/DEVICE will give you a device’s SCSI ID.)

Clean & Test

  • Remove the /etc/lvm/cache/.cache file if it already exists.
  • Run vgscan and double-check the output from pvs, vgs, and lvs.
  • Make that the root volume is still visible, especially if it’s on an LVM logical disk, as this could cause a panic on boot.
  • The filter can also be tested on the fly without having to edit /etc/lvm/lvm.conf or run the LVM command with the –config argument. Keep in mind that this will not affect the server’s configuration permanently. After testing, make sure to add the functional filter in /etc/lvm/lvm.conf.
  • Consider the following scenario:
# lvs --config 'devices{ filter = [ "a|/dev/hda2|", "a|/dev/mapper/mpath|", "r|.*|" ] global_filter = [ "a|/dev/hda2|", "a|/dev/mapper/mpath|", "r|.*|" ] }'

Rebuild initramfs so that the system’s new LVM filter is applied at boot time.

Leave a Reply