Linux – “fdisk -l” like list of partitions and their types for LVM logical volumes

linuxlvmpartition

You know how "fdisk -l" lists drive partition tables and shows the partition id/types for each partition?

Is there a similar way to get the partition id for LVM logical volumes?

EDIT: I'm aware of "lvs", which is mostly what I'm looking for (it gives me the list of logical volumes, kind of like "fdisk -l"… except it would also be useful to know what the partition types of the logical volumes (which I like to think of as "virtual partitions") are. That info is what "fdisk -l" lists on the last two columns on the right. (Such as "8e" for a physical LVM partition, or "83" for Linux ext, etc.).

The tool I'm looking for may not be part of LVM; maybe just some other utility that can print partition ids/types given a partition?

Best Answer

The partition ID for Linux LVM is 8e, reported by fdisk.

$ sudo fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00008ec7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1013     8136891   8e  Linux LVM
/dev/sda2            1014        1044      249007+   5  Extended
/dev/sda5            1014        1044      248976   83  Linux

LVM is an abstraction layer on top of the storage device to make it easier for you to manage it. I'm not sure what information beyond what fdisk provides you want, because the partition ID for LVM is displayed. However, for additional information about LVM logical volumes, you can use 'lvscan', 'lvs' and 'lvdisplay'.

$ sudo lvscan 
  ACTIVE            '/dev/ops1test/root' [7.35 GB] inherit
  ACTIVE            '/dev/ops1test/swap_1' [388.00 MB] inherit

$ sudo lvs 
  LV     VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  root   ops1test -wi-ao   7.35G                                      
  swap_1 ops1test -wi-ao 388.00M                                      

$ sudo lvdisplay
  --- Logical volume ---
  LV Name                /dev/ops1test/root
  VG Name                ops1test
  LV UUID                BfKOpy-L7Ql-905o-7tFk-nnsV-0c7I-w4g9y6
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                7.35 GB
  Current LE             1881
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Name                /dev/ops1test/swap_1
  VG Name                ops1test
  LV UUID                8SNfQ9-Hlfk-Edsb-vmL1-DeE3-nBRR-YAM1dV
  LV Write Access        read/write
  LV Status              available
  # open                 2
  LV Size                388.00 MB
  Current LE             97
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

Similarly, you can learn information about the volume group itself with 'vgscan', 'vgs' and 'vgdisplay'.

$ sudo vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "ops1test" using metadata type lvm2

$ sudo vgs
  VG       #PV #LV #SN Attr   VSize VFree 
  ops1test   1   2   0 wz--n- 7.76G 32.00M

$ sudo vgdisplay
  --- Volume group ---
  VG Name               ops1test
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               7.76 GB
  PE Size               4.00 MB
  Total PE              1986
  Alloc PE / Size       1978 / 7.73 GB
  Free  PE / Size       8 / 32.00 MB
  VG UUID               ofpvks-2EDZ-limu-0wAh-tYUN-ISG3-mSS65O