Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a volume group (VG) that contains two physical volumes (PV). Several logical volumes (LV) in the VG are likely to use extents on both PVs.

Is there a way to tell which LVs occupy space on which PVs?

share|improve this question
    
Here are all the commands you'll need to start with lvm : lvdisplay, pvdisplay, vgdisplay – user130370 Dec 28 '12 at 10:09
up vote 24 down vote accepted

The pvdisplay command has a -m option to show the mapping of physical extents to logical volumes and logical extents.

I have set up the following situation on a test machine:

  • 3 disks of 1GB each added to the system and used as physical volumes for vg_test
  • 6 logical volumes made with various sizes (ranging from 300M to 1.1G) so that they are spread over the physical volumes

Running pvdisplay -m on this machine results in the following output:

[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

As you can see, You get a nice overview of where the extents for each of the 6 logical volumes are.

share|improve this answer
3  
Wow, I have been using LVM for years and were completely unaware of the -m switch. Thanks! – Paul Dec 28 '12 at 10:32
    
+1 Thanks, I didn't know it! – Jan Marek Dec 28 '12 at 10:38

I use:

lvs -o +devices

...which I find a little easier to interpret.

share|improve this answer
3  
One thing, it doesn't work with lvm mirrors enabled. There it'll just show "lvname_rimage0,lvname_rimage1" instead of the underlying disks. (not your fault, the command and the mirroring itself is badly designed). Even then it's still good to spot unmirrored lv's. Just be careful not to fully rely on the output because the above. – Florian Heigl Jan 7 '15 at 12:56

lvdisplay -m will list its physical segments:

# 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

By adding the -a option, you can also see the volumes that are set up by raid1-mirrored volumes:

# 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

For each mirror, you will see two volumes, {volume_name}_rmeta_{n} (containing the raid meta data) and {volume_name}_rimage_{n} (containing the actual data), where {volume_name} is the name of the logical volume and {n} is the number of the mirror (starting at 0).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.