How to find the physical volume(s) that hold a logical volume in LVM
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?
Solution 1:
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.
Solution 2:
I use:
lvs -o +devices
...which I find a little easier to interpret.
Solution 3:
LVM is a flexible abstraction layer between physical disk up to the filesystem (disk ⇒ partition ⇒ LVM's physical volume [PV] ⇒ LVM's volume group [VG] ⇒ LVM logical volume [LV] ⇒ filesystem).
Due to some LVM features (aggregation, mirror, stripes, snapshot...), the physical layout can become complex... thus some caveats:
- Use lvs manpage about
--all
to view internal details (of mirrored volumes), if wanted. - Obviously, when you run a command for a given objet, only that object's parents and children are show (which may be incomplete, if LV is spanning on multiple PV for example)
For a quick overview, I recommend lsblk (which is a standard tool, not LVM specific).
$ 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 specific tools
To get LVM's internal view and details, use LVM commands:
- Lists : use the
lvs
andpvs
commands with option--segments
- Detailed view: use the
lvdisplay
andpvdisplay
commands with option-m
LVM tools exmples
List the physical segments used by a logical volume :
$ 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
same with more details:
$ 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)
List the physical extents of a given LV. Useful to move those segments (using pvmove
):
$ lvs /dev/vg_ssd/lv_videos -o seg_pe_ranges
PE Ranges
/dev/sdb1:12729-18090
/dev/sdb1:3534-5339
The opposite way, list the logical volume (segments) inside a given Physical Volume:
$ 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
List the physical segments of a given logical volume, among other information:
$ 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
Display the Logical volume associated with a given physical volume , among other information:
$ 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
Complex command, but full list :
$ 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
Solution 4:
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
).