Course contentsShow
← Linux
Lesson 681 of 1,8197. Storage Management and Logical VolumesFree lesson

LVM configuration file tuning

Modify global LVM settings to customize volume scanning and filter behaviors.

In this lesson, you will learn how to fine-tune LVM’s global behavior by editing the /etc/lvm/lvm.conf file to control how the system scans your disks.

The Role of lvm.conf

While you usually manage volumes using commands like pvcreate or lvcreate, the core logic of how LVM discovers devices is governed by the global configuration file: /etc/lvm/lvm.conf. By default, LVM scans every single block device on your system to see if it contains an LVM header. On servers with large SAN arrays or many temporary USB drives, this scanning process can be slow and may even cause system instability if LVM tries to probe hardware that shouldn't be touched.

Customizing Filters

The most common tuning task is defining a filter. Filters tell LVM explicitly which devices to scan and which to ignore. You can find the filter setting within the devices section of your configuration file.

For example, if you want to ensure LVM only scans your main hard drives (/dev/sda) and ignores everything else (such as loopback devices or virtual CD-ROMs), you would set a pattern:

devices {
    # Scan only /dev/sda and ignore all other devices
    filter = [ "a|^/dev/sda$|", "r|.*|" ]
}
  • a stands for accept (include the device).
  • r stands for reject (exclude the device).
  • The .* acts as a wildcard, meaning "reject everything else" that wasn't already accepted.

Why Tune This?

By narrowing the scope of the device scan, you significantly speed up commands like pvs and vgs because the system stops wasting time polling irrelevant hardware. Additionally, this prevents LVM from accidentally grabbing a partition that you might be using for a completely different purpose, such as a raw database partition or a swap space on an external drive.

Always remember to run vgscan after modifying lvm.conf to force LVM to refresh its cache and recognize your new filtering rules. Be extremely careful; a bad filter can make your Volume Groups disappear from the system's view until you correct the configuration!

Key Takeaway: Modifying the filter setting in /etc/lvm/lvm.conf allows you to optimize performance and protect specific hardware by explicitly telling LVM which devices to include or ignore during its system-wide scan.