22

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?

1
  • 1
    Try cat /etc/fstab to display the type of the filesystem, even with lvm... Sounds obvious, but it answers the question...
    – user331553
    Jan 12, 2016 at 21:48

11 Answers 11

16

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
1
  • 4
    Also: pvs, pvdisplay and pvscan for getting data about the physical volumes...
    – freiheit
    Jun 20, 2009 at 6:05
10

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 | sed 's/-/--/' | while read lv vg rest; do file --dereference --special-files "/dev/mapper/$(echo $vg)-$lv"; done

Here is an example for the output that this command would give (truncated a little):

[...]
/dev/mapper/VolGroup00-LogVol00: Linux rev 1.0 ext4 filesystem data, UUID=b000000e-00f0-0cde-b000-fa0d000ddc00 (extents) (64bit) (large files) (huge files)
[...]
4
  • 2
    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, 2013 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, 2013 at 18:52
  • 2
    This should be the accepted answer!
    – lanoxx
    Nov 4, 2015 at 12:23
  • 1
    Does not work when when you have dashes in your VG name, these are doubled, updated the answer. Possibly the same problem applies for LV names, but I didn't test that.
    – sjas
    Aug 26, 2016 at 9:20
9

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
2
  • Not answering the question, but the only way to check if your LV is fragmented or not. Upvote, haven't seen this anywhere else yet.
    – sjas
    Aug 26, 2016 at 9:11
  • This was what I was looking for, what devices are in a logical volume and yours was the only answer I've seen. Thank you. Jul 19, 2022 at 17:38
6

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.

5

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).

4

Does lsblk provide the information you need ?

[root@localhost ~]# lsblk -o TYPE,NAME,KNAME,UUID,MOUNTPOINT,SIZE                                                                                                                                                                        
TYPE NAME                KNAME UUID                                   MOUNTPOINT  SIZE
rom  sr0                 sr0   2014-07-04-15-59-23-00                             362M
disk vda                 vda                                                        1G
part └─vda1              vda1  7eadd712-6571-4722-8a5e-5d419176f6dc   /boot      1023M
disk vdb                 vdb   eVbl9d-dxf0-yqiV-evZC-FHPB-RrZb-eb1897              20G
lvm  ├─vg_system-lv_swap dm-0  44bb22f8-d8c6-482c-8763-36ee58c2528e   [SWAP]        1G
lvm  ├─vg_system-lv_usr  dm-1  c1f9ac62-17a3-4dfa-88b6-6a26394dd270   /usr          2G
lvm  ├─vg_system-lv_root dm-2  6724461a-2401-42ec-8180-fb7582040b68   /            10G
lvm  ├─vg_system-lv_var  dm-3  f2044fb7-5a64-4ae3-8407-891f75aba534   /var          2G
lvm  └─vg_system-lv_home dm-4  8ad80cce-bdf4-43e9-b755-b987169ed062   /home         2G
[root@localhost ~]# 
1

If you look at the previous post from "Mark V" you will see the lsblk command was used.

This is a great option, however the OP asked for the type which was omitted from most of the answers. Using lsblk from above and adding "FSTYPE" you get the expected type:

# lsblk -o TYPE,NAME,KNAME,UUID,MOUNTPOINT,SIZE,FSTYPE
TYPE NAME               KNAME UUID                                   MOUNTPOINT  SIZE FSTYPE
disk fd0                fd0                                                        4K
disk sda                sda                                                      100G
part ├─sda1             sda1  a6f1731f-e2bf-4dae-a443-269b079388a6   /boot         1G xfs
part ├─sda2             sda2  6CCtv5-HHYq-aXDm-m4jj-IpD3-rfv7-AI57D9              49G 
LVM2_member
lvm  │ ├─cl_hadron-root dm-0  0c8bfb8b-ec32-4152-9abd-b6bc5c475b00   /            97G xfs
lvm  │ └─cl_hadron-swap dm-1  8aeeadab-69da-49ff-991d-dad8857fb82b   [SWAP]        2G 
swap
# 
0

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).

0

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

0

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.

0

I think this one-line command could help:

for i in $(df -h | grep mapper | cut -d" " -f1); do echo $i; lvdisplay --maps $i | grep "Physical volume"; done

The output is similar to this:

/dev/mapper/myserver-root
    Physical volume /dev/sda5
/dev/mapper/SambaShares
    Physical volume /dev/sdb1
    Physical volume /dev/sdo1
    Physical volume /dev/sdp
/dev/mapper/Test--Disc
    Physical volume /dev/sdf1
    Physical volume /dev/sdg1
    Physical volume /dev/sdh1
    Physical volume /dev/sdi1
/dev/mapper/Clonezilla-partimag
    Physical volume /dev/sdk1
    Physical volume /dev/sdj1
    Physical volume /dev/sdl1
    Physical volume /dev/sdm1
    Physical volume /dev/sdn1
    Physical volume /dev/sdq1

You must log in to answer this question.