Controlling LVM Device Scans with Filters

At startup, the vgscan command is run to scan the block devices on the system looking for LVM labels, to determine which of them are physical volumes and to read the metadata and build up a list of volume groups. The names of the physical volumes are stored in the cache file of each node in the system, /etc/lvm/.cache. Subsequent commands may read that file to avoiding rescanning.

You can control which devices LVM scans by setting up filters in the lvm.conf configuration file. The filters consist of a series of simple regular expressions that get applied to the device names in the /dev directory to decide whether to accept or reject each block device found.

The following examples show the use of filters to control which devices LVM scans. Note that some of these examples do not necessarily represent best practice, as the regular expressions are matched freely against the complete pathname. For example, a/loop/ is equivalent to a/.*loop.*/ and would match /dev/solooperation/lvol1.

The following filter adds all discovered devices, which is the default behavior as there is no filter configured in the configuration file:

filter = [ "a/.*/" ]

The following filter removes the cdrom device in order to avoid delays if the drive contains no media:

filter = [ "r|/dev/cdrom|" ]

The following filter adds all loop and removes all other block devices:

filter = [ "a/loop.*/", "r/.*/" ]

The following filter adds all loop and IDE and removes all other block devices:

filter =[ "a|loop.*|", "a|/dev/hd.*|", "r|.*|" ]

The following filter adds just partition 8 on the first IDE drive and removes all other block devices:

filter = [ "a|^/dev/hda8$|", "r/.*/" ]

For more information on the lvm.conf file, see Appendix B, The LVM Configuration Files and the lvm.conf(5) man page.

 

Scanning Disks for Volume Groups to Build the Cache File

The vgscan command scans all supported disk devices in the system looking for LVM physical volumes and volume groups. This builds the LVM cache in the /etc/lvm/.cache file, which maintains a listing of current LVM devices.

LVM runs the vgscan command automatically at system startup and at other times during LVM operation, such as when you execute a vgcreate command or when LVM detects an inconsistency. You may need to run the vgscan command manually when you change your hardware configuration, causing new devices to be visible to the system that were not present at system bootup. This may be necessary, for example, when you add new disks to the system on a SAN or hotplug a new disk that has been labeled as a physical volume.

You can define a filter in the lvm.conf file to restrict the scan to avoid specific devices. For information on using filters to control which devices are scanned, see Section 4.6, “Controlling LVM Device Scans with Filters”.

Old News


Last modified: October 03, 2017