[Gllug] Mapping from disk block to LVM partitions

Richard Jones rich at annexia.org
Sun Dec 6 16:14:03 UTC 2009


On Sun, Dec 06, 2009 at 12:22:17PM +0000, Rich Walker wrote:
> Smartd finding disk errors on raid array recheck. Raid array is used for
> LVM. What's the fastest/easiest way to get from disk block number to LVM
> partition?

Not sure about "fastest" but I have spent quite a long time decoding
LVM disk information a while back.

The information is stored in plain text in the first few megabytes of
the PV.  Actually there are likely to be several copies, because the
metadata is stored in a circular buffer, where new metadata is written
after, not on top of, old metadata (so that there is some possibility
of rolling back to earlier versions).

The metadata itself is in plain text as I said, in a simple C-like
recursive format.

# pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/dm-0  vg_trick lvm2 a-   931.31G 575.38G

# strings /dev/dm-0
LABELONE
LVM2 0013l0DTj3QUp1TfM5jzMbfX1PTt0cP8C9a
 LVM2 x[5A%r0N*>
[...]
# Generated by LVM2 version 2.02.45 (2009-03-03): Thu May 14 11:50:40 2009
contents = "Text Format Volume Group"
version = 1
description = ""
creation_host = "user-desktop.home.annexia.org" # Linux user-desktop.home.annexi
a.org 2.6.29.1-102.fc11.x86_64 #1 SMP Mon Apr 20 15:33:38 EDT 2009 x86_64
creation_time = 1242298240      # Thu May 14 11:50:40 2009
vg_trick {
id = "FPsBXd-JynR-HvhD-0FRI-Z8qe-5HrU-brjJYQ"
seqno = 2
status = ["RESIZEABLE", "READ", "WRITE"]
flags = []
extent_size = 8192
max_lv = 0
max_pv = 0
physical_volumes {
pv0 {
id = "3l0DTj-3QUp-1TfM-5jzM-bfX1-PTt0-cP8C9a"
device = "/dev/dm-0"
status = ["ALLOCATABLE"]
flags = []
dev_size = 1953106424
pe_start = 384
pe_count = 238416
logical_volumes {
lv_root {
id = "bQDbMV-eEdv-JuE3-UxYw-GJPw-PlSb-UnaH7N"
status = ["READ", "WRITE", "VISIBLE"]
flags = []
segment_count = 1
segment1 {
start_extent = 0
extent_count = 62500
type = "striped"
stripe_count = 1        # linear
stripes = [
"pv0", 0
 ....

It's possible with a bit of effort to go from this to the actual
mapping of LVs to blocks on the disk, or vice versa.

No idea if there is an easier way.  It's the sort of thing that
libguestfs could probably be extended to do ...

Rich.

-- 
Richard Jones
Red Hat
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list