Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

8 Answers 8

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
share|improve this answer
2  
Also: pvs, pvdisplay and pvscan for getting data about the physical volumes... –  freiheit Jun 20 '09 at 6:05

Logical volumes don't have a concept of a "type", they're just block devices. If you want to examine the contents of a block device and determine what is in it, you might want to look at the blkid tool, which does exactly that.

share|improve this answer

Logical volumes doesn't have a "type" like old DOS partitions do. Like Unix files, you'll have to read them to find out what they are. Something like this should do the trick:

lvs --all --noheadings | while read lv vg rest; do file --dereference --special-files "/dev/mapper/$vg-$lv"; done
share|improve this answer
    
Great Answer. It seems like no one else understood what the OP was asking for. I had to make one change to your script: I added the --dereference option to the file command. Each LV is linked to /dm-X by the device mapper. –  codewaggle Apr 24 '13 at 3:03
1  
@codewaggle Thanks; option added. When I wrote the answer back in '09, the option was not needed, but times change. –  Teddy Apr 28 '13 at 18:52

LVM is an abstraction above physical disks.

Logical volumes (which you can format and place files on) are allocated from volume groups, which may be made up of one or more physical extents - the actual physical disk partitions.

Your question is a little unclear. If you would like to show which disk partitions a Logical Volume is physically residing on, lvdisplay --maps may help:

# lvdisplay --maps
  --- Logical volume ---
  LV Name                /dev/VolGroup00/root
  VG Name                VolGroup00
  LV UUID                xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.00 GB
  Current LE             160
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Segments ---
  Logical extent 0 to 159:
    Type                linear
    Physical volume     /dev/sda2
    Physical extents    0 to 159
share|improve this answer
    
Thanks, I have been searching for this. –  Question Overflow Jan 28 at 14:21

1) A logical volume is NOT a (physical) disk partition. It is a virtual block device created inside Linux kernel with Device Mapper. It's a technology one can use to setup a single block device using two disk partitions as well as two block devices using a single disk partition, and much more.

# dmsetup targets

If you want to know more about DM visit it's home page, check it's manual pages, read RedHat manual or for instance this article. It's great technology only mentioned in Wikipedia.

2) For instance on my home computer I have physical disk partitions as well as DM devices (logical volumes).

# cat /proc/partitions

major minor #blocks name

   3     0   80043264 hda
   3     1     204800 hda1
   3     2   79831029 hda2
   3    64   19589976 hdb
   3    65     104391 hdb1
   3    66   19478812 hdb2
 253     0   17432576 dm-0
 253     1    2031616 dm-1
 253     2   77762560 dm-2
 253     3    2064384 dm-3

Primarily they don't have any type or ID, they are defined with just the start sector numer and the length.

# dmsetup status -j 253 -m 0
0 34865152 linear

So dm-0 is a fragment consisting of 34865152 sectors of some physical device.

# dmsetup deps -j 253 -m 0
1 dependencies  : (3, 66)

And this device is /dev/hdb2 partition!

# fdisk /dev/hdb
Command (m for help): p
   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1   *           1          13      104391   83  Linux
/dev/hdb2              14        2438    19478812+  8e  Linux LVM

And it is LVM (8e) type partition, mentioned by timberman.

# pvs
  PV         VG         Fmt  Attr PSize  PFree
  /dev/hda2  VolGroup   lvm2 a-   76,13G    0 
  /dev/hdb2  VolGroup00 lvm2 a-   18,56G    0

This single (physical) disk partition can hold logical volumes within a group. I have two disks so there are two such groups and each group holds two logical devices.

# lvs
  LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  lv_root  VolGroup   -wi-a- 74,16G                                      
  lv_swap  VolGroup   -wi-a-  1,97G                                      
  LogVol00 VolGroup00 -wi-ao 16,62G
  LogVol01 VolGroup00 -wi-ao  1,94G

So dm-0 and dm-1 are two LVs (lvroot and lvswap) created on my /dev/hdb2 partition of my first disk (with CentOS) while dm-2 and dm-3 are LVs created on my /dev/hda2 partition of my second disk (with Fedora).

Logical devices can have labels (UUIDs). You can check them with lvdisplay command, mentioned above. But they are just labels, which you can use (-u) instead of major, minor numbers (-j -m switches).

share|improve this answer

Logical volumes do not have a partition ID or type. They are composed of physical extents (PE) which may be spread over multiple physical volumes (PV), each of which could be a partition (e.g. /dev/sda2) or a complete disk (e.g. /dev/sdb).

share|improve this answer

probably not needed but I learned a little myself here http://www.linuxconfig.org/Linux_lvm_-_Logical_Volume_Manager

share|improve this answer

Partition type id is stored only in the partition table, not on the partition itself. On the other hand, LVM logical volumes are normally treated like individual partitions, not as disks, so there's no partition table and therefore no partition type id to look for.

Also note that the type id is only for informative purposes in Linux (this is not true for Windows, though). It has no bearing on the contents and the filesystem of that partition.

share|improve this answer

Your Answer

 
discard

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