如何查找 LVM 中保存逻辑卷的物理卷

如何查找 LVM 中保存逻辑卷的物理卷

我有一个包含两个物理卷 (PV) 的卷组 (VG)。VG 中的几个逻辑卷 (LV) 可能使用两个 PV 上的区段。

有没有办法判断哪些 LV 占用了哪些 PV 上的空间?

答案1

pvdisplay命令有一个-m选项可以显示物理范围到逻辑卷和逻辑范围的映射。

我在测试机上设定了如下情形:

  • 将 3 个 1GB 的磁盘添加到系统并用作 vg_test 的物理卷
  • 6 个逻辑卷,大小各异(从 300M 到 1.1G),分布在物理卷上

在此机器上运行pvdisplay -m结果如下:

[root@centos6 ~]# pvdisplay -m
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg_test
  PV Size               1.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              255
  Free PE               5
  Allocated PE          250
  PV UUID               eR2ko2-aKRf-uCfq-O2L0-z6em-ZYT5-23YhKb

  --- Physical Segments ---
  Physical extent 0 to 74:
    Logical volume  /dev/vg_test/one
    Logical extents 0 to 74
  Physical extent 75 to 149:
    Logical volume  /dev/vg_test/two
    Logical extents 0 to 74
  Physical extent 150 to 249:
    Logical volume  /dev/vg_test/four
    Logical extents 0 to 99
  Physical extent 250 to 254:
    FREE

  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               vg_test
  PV Size               1.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              255
  Free PE               10
  Allocated PE          245
  PV UUID               rByjXK-NA6D-ifnY-lKdF-eFWg-Ndou-psGJUq

  --- Physical Segments ---
  Physical extent 0 to 124:
    Logical volume  /dev/vg_test/three
    Logical extents 0 to 124
  Physical extent 125 to 224:
    Logical volume  /dev/vg_test/five
    Logical extents 0 to 99
  Physical extent 225 to 244:
    Logical volume  /dev/vg_test/six
    Logical extents 255 to 274
  Physical extent 245 to 254:
    FREE

  --- Physical volume ---
  PV Name               /dev/sdd
  VG Name               vg_test
  PV Size               1.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              255
  Free PE               0
  Allocated PE          255
  PV UUID               TCJnZM-0ss9-o5gY-lgD3-7Kq6-18IH-sN04To

  --- Physical Segments ---
  Physical extent 0 to 254:
    Logical volume  /dev/vg_test/six
    Logical extents 0 to 254

如您所见,您可以很好地了解 6 个逻辑卷中的每个卷的范围的位置。

答案2

我用:

lvs -o +devices

...我发现这更容易解释一些。

答案3

LVM 是物理磁盘和文件系统之间的灵活抽象层(磁盘⇒分区⇒LVM 的物理卷 [PV]⇒LVM 的卷组 [VG]⇒LVM 逻辑卷 [LV]⇒文件系统)。

由于某些 LVM 特性(聚合、镜像、条带、快照...),物理布局可能变得复杂...因此需要注意一些事项:

  • 使用lvs如果需要,可以参阅手册页来--all查看(镜像卷的)内部详细信息。
  • 显然,当您为给定对象运行命令时,只会显示该对象的父对象和子对象(例如,如果 LV 跨越多个 PV,则可能不完整)

为了快速概览,我建议lsblk(这是一个标准工具,不是 LVM 专用的)。

$ lsblk
NAME                     MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                        8:0    0 223,6G  0 disk 
├─sda1                     8:1    0   350M  0 part 
├─sda2                     8:2    0    29G  0 part 
├─sda3                     8:3    0   488M  0 part /boot
├─sda4                     8:4    0     1K  0 part 
└─sda5                     8:5    0 193,8G  0 part 
  ├─vg_ssd-lv_root_solid 254:0    0  13,3G  0 lvm  /
  ├─vg_ssd-lv_srv_solid  254:2    0  46,6G  0 lvm  /srv
  └─vg_ssd-lv_home_solid 254:3    0   107G  0 lvm  /home
sdb                        8:16   0  74,5G  0 disk 
└─sdb1                     8:17   0  74,5G  0 part 
  ├─vg_ssd-lv_swap_solid 254:1    0   3,7G  0 lvm  [SWAP]
  └─vg_ssd-lv_videos     254:4    0    28G  0 lvm  /mnt/videos

LVM 特定工具

要获取 LVM 的内部视图和详细信息,请使用 LVM 命令:

  • 列表:使用lvspvs 命令以及选项--segments
  • 详细视图:使用lvdisplaypvdisplay 命令以及选项-m

LVM 工具示例

列出逻辑卷使用的物理段:

$ lvs --segments /dev/vg_ssd/lv_videos
LV        VG     Attr       #Str Type   SSize 
lv_videos vg_ssd -wi-ao----    1 linear 20,95g
lv_videos vg_ssd -wi-ao----    1 linear  7,05g

同样,还有更多详细信息:

$ lvs --segments /dev/vg_ssd/lv_videos -o +lv_size,devices
  LV        VG     Attr       #Str Type   SSize  LSize  Devices         
  lv_videos vg_ssd -wi-ao----    1 linear 20,95g 28,00g /dev/sdb1(12729)
  lv_videos vg_ssd -wi-ao----    1 linear  7,05g 28,00g /dev/sdb1(3534) 

列出给定 LV 的物理范围。移动这些段很有用(使用pvmove):

$ lvs  /dev/vg_ssd/lv_videos -o seg_pe_ranges
  PE Ranges
  /dev/sdb1:12729-18090
  /dev/sdb1:3534-5339  

相反的方式,列出给定物理卷内的逻辑卷(段):

$ pvs  /dev/sdb1  --segments  -o +lv_name,lv_size
  PV         VG     Fmt  Attr PSize  PFree  Start SSize LV            LSize 
  /dev/sdb1  vg_ssd lvm2 a--  74,53g 22,80g     0  3534                   0 
  /dev/sdb1  vg_ssd lvm2 a--  74,53g 22,80g  3534  1806 lv_videos     28,00g
  /dev/sdb1  vg_ssd lvm2 a--  74,53g 22,80g  5340  1316                   0 
  /dev/sdb1  vg_ssd lvm2 a--  74,53g 22,80g 11776   953 lv_swap_solid  3,72g
  /dev/sdb1  vg_ssd lvm2 a--  74,53g 22,80g 12729  5362 lv_videos     28,00g
  /dev/sdb1  vg_ssd lvm2 a--  74,53g 22,80g 18091   988                   0 

列出给定逻辑卷的物理段以及其他信息:

$ lvdisplay -m /dev/vg_ssd/lv_videos
[..]
  --- Segments ---
  Logical extents 0 to 5361:
    Type        linear
    Physical volume /dev/sdb1
    Physical extents    12729 to 18090

  Logical extents 5362 to 7167:
    Type        linear
    Physical volume /dev/sdb1
    Physical extents    3534 to 5339

显示与给定物理卷关联的逻辑卷以及其他信息:

$ pvdisplay -m /dev/sdb1
[..]
  --- Physical Segments ---
  Physical extent 0 to 3533:
    FREE
  Physical extent 0 to 5339:
    Logical volume  /dev/vg_ssd/lv_videos
    Logical extents 5362 to 7167
  Physical extent 5340 to 11775:
    FREE
  Physical extent 11776 to 12728:
    Logical volume  /dev/vg_ssd/lv_swap_solid
    Logical extents 0 to 952
  Physical extent 12729 to 18090:
    Logical volume  /dev/vg_ssd/lv_videos
    Logical extents 0 to 5361
  Physical extent 18091 to 19078:
    FREE

命令复杂,但列表完整:

$ pvs   --segments  -o pv_name,pv_size,seg_size,vg_name,lv_name,lv_size,seg_pe_ranges
  PV         PSize   SSize   VG     LV            LSize   PE Ranges            
  /dev/sda5  193,79g   9,31g vg_ssd lv_root_solid  13,31g /dev/sda5:0-2383     
  /dev/sda5  193,79g   3,72g vg_ssd lv_home_solid 107,00g /dev/sda5:2384-3336  
  /dev/sda5  193,79g  46,56g vg_ssd lv_srv_solid   46,56g /dev/sda5:3337-15256 
  /dev/sda5  193,79g  60,00g vg_ssd lv_home_solid 107,00g /dev/sda5:15257-30616
  /dev/sda5  193,79g 200,00m vg_ssd lv_home_solid 107,00g /dev/sda5:30617-30666
  /dev/sda5  193,79g   1,05g vg_ssd                    0                       
  /dev/sda5  193,79g   8,00g vg_ssd lv_home_solid 107,00g /dev/sda5:30937-32984
  /dev/sda5  193,79g   4,00g vg_ssd lv_root_solid  13,31g /dev/sda5:32985-34008
  /dev/sda5  193,79g  20,00g vg_ssd lv_home_solid 107,00g /dev/sda5:34009-39128
  /dev/sda5  193,79g   9,80g vg_ssd lv_home_solid 107,00g /dev/sda5:41689-44198
  /dev/sda5  193,79g   1,28g vg_ssd lv_home_solid 107,00g /dev/sda5:44199-44525
  /dev/sda5  193,79g  15,86g vg_ssd                    0                       
  /dev/sda5  193,79g   4,00g vg_ssd lv_home_solid 107,00g /dev/sda5:48587-49610
  /dev/sdb1   74,53g  13,80g vg_ssd                    0                       
  /dev/sdb1   74,53g   7,05g vg_ssd lv_videos      28,00g /dev/sdb1:3534-5339  
  /dev/sdb1   74,53g   5,14g vg_ssd                    0                       
  /dev/sdb1   74,53g   3,72g vg_ssd lv_swap_solid   3,72g /dev/sdb1:11776-12728
  /dev/sdb1   74,53g  20,95g vg_ssd lv_videos      28,00g /dev/sdb1:12729-18090
  /dev/sdb1   74,53g   3,86g vg_ssd                    0                       

答案4

lvdisplay -m将列出其物理段:

# lvdisplay -m
  --- Logical volume ---
  LV Path                /dev/vg/swap
  LV Name                swap
  VG Name                vg
  LV UUID                TlxZzz-11Z3-u3K3-0ULD-AZV6-c4ug-jp7YVP
  LV Write Access        read/write
  LV Creation host, time edeltraud, 2015-03-12 12:43:09 +0100
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     512
  Block device           254:21

  --- Segments ---
  Logical extents 0 to 511:
    Type                striped
    Stripes             2
    Stripe size         64.00 KiB
    Stripe 0:
      Physical volume   /dev/sdc1
      Physical extents  2561 to 2816
    Stripe 1:
      Physical volume   /dev/sda1
      Physical extents  241027 to 241282

通过添加-a选项,您还可以看到由-mirrored volumes设置的卷raid1

# lvdisplay -am
  --- Logical volume ---
  Internal LV Name       srv_rimage_0
  VG Name                vg
  LV UUID                IJTT9w-2aX5-aqR5-VY4Z-Lqtp-L3cP-jkzNnx
  LV Write Access        read/write
  LV Creation host, time edeltraud, 2015-12-13 00:10:03 +0100
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:39

  --- Segments ---
  Logical extents 0 to 12799:
    Type                linear
    Physical volume     /dev/sdb4
    Physical extents    7683 to 20482


  --- Logical volume ---
  Internal LV Name       srv_rmeta_0
  VG Name                vg
  LV UUID                YyyVAa-dab7-8Jxg-JzpS-Yf3k-4SDH-654cqf
  LV Write Access        read/write
  LV Creation host, time edeltraud, 2015-12-13 00:10:03 +0100
  LV Status              available
  # open                 1
  LV Size                4.00 MiB
  Current LE             1
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:38

  --- Segments ---
  Logical extents 0 to 0:
    Type                linear
    Physical volume     /dev/sdb4
    Physical extents    7682 to 7682

对于每个镜像,您将看到两个卷,{volume_name}_rmeta_{n}(包含 raid 元数据)和{volume_name}_rimage_{n}(包含实际数据),其中{volume_name}是逻辑卷的名称,{n}是镜像的编号(从 开始0)。

相关内容