Show Table of Contents
4.5. 使用过滤器控制 LVM 设备扫描
启动时,会运行
vgscan 命令,扫描系统中的块设备,查找 LVM 标签,以决定哪些是物理卷。同时还会读取元数据并建立卷组列表。物理卷的名称保存在系统中每个节点的缓存文件 /etc/lvm/cache/.cache 中。之后的命令可读取那个文件以避免重复扫描。
可通过在
lvm.conf 配置文件中设定过滤器控制设备 LVM 扫描。lvm.conf 文件中的过滤器由一系列简单正则表达式组成,应用于 /dev 目录中的设备名以决定接受或者拒绝每个找到的块设备。
下面的示例演示了使用过滤器控制 LVM 扫描的设备。注:这些示例不一定代表最佳实践,因为正则表达式与完整路径名完全匹配。例如:
a/loop/ 等同与 a/.*loop.*/,并与 /dev/solooperation/lvol1 映射。
下面的过滤器添加所有找到的设备,这是默认行为,因为在配置文件中没有配置任何过滤器:
filter = [ "a/.*/" ]
下面的过滤器删除 cdrom 设备,以避免在该驱动器中不包含任何介质时会造成延迟:
filter = [ "r|/dev/cdrom|" ]
下面的过滤器添加所有回路并删除其他所有块设备:
filter = [ "a/loop.*/", "r/.*/" ]
下面的过滤器添加所有回路和 IDE,并删除其他所有块设备:
filter =[ "a|loop.*|", "a|/dev/hd.*|", "r|.*|" ]
下面的过滤器只在第一个 IDE 驱动器中添加分区 8 并删除其他所有块设备:
filter = [ "a|^/dev/hda8$|", "r/.*/" ]
注意
lvmetad 守护进程处于运行状态时,执行 pvscan --cache device 命令时不会应用 /etc/lvm/lvm.conf 文件中的 filter = 设置。要过滤设备,则需要使用 global_filter = 设定。LVM 不会打开无法进行全局过滤的设备,且再也不会对其进行扫描。可能会需要使用全局过滤器,例如:在 VM 中使用 LVM 设备,且不想让该物理主机扫描 VM 中设备的内容。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.