17

I am trying to understand how / where LVM stores its configuration data.

  • Does pvcreate /dev/sdb write any metadata to /dev/sdb? if so what is written?
  • Where does vgcreate data /dev/sdb /dev/sdc store configuration of the volume group?
  • Where does LVM store the mapping between logical extents and physical extents?
  • Is there any machine specific configuration in a LVM configuration?
  • Suppose I have machine with 2 disks configured into a logical volume can I just take those disks out the machine and put them in another machine and expect that the logical volume will work in the new machine?
10

Does pvcreate /dev/sdb write any metadata to /dev/sdb? if so what is written?

If you pass a -vv flag to the pvcreate command it makes the command more verbose and you will see that pvcreate creates a metadata area on the disk.

 Writing physical volume data to disk "/dev/sdc1"
        lvmcache: /dev/sdc1: now in VG #orphans_lvm2 (#orphans_lvm2) with 0 mdas
        Creating metadata area on /dev/sdc1 at sector 8 size 2040 sectors
        Opened /dev/sdc1 RW O_DIRECT
        /dev/sdc1: block size is 1024 bytes
        /dev/sdc1: physical block size is 512 bytes
        /dev/sdc1: Preparing PV label header xxx.xxxxx.xxxxxxxxxxxxxxx

      /dev/sdc1: Writing label to sector 1 with stored offset 32.

What is written to the metadata area?

I am not aware of a command that you can use to view the metadata, but the command vgcfgbackup can be used to backup the metadata and you can open a backup file thus created to view the metadata

vgcfgbackup -f /path/of/your/choice/file <your_vg_name>

The /path/of/your/choice/file created by the above command will contain the PV, VG and LVM metadata. One of the sections will look like below:

physical_volumes {

                pv0 {
                        id = "abCDe-TuvwX-DEfgh-daEb-Xys-6Efcgh-LkmNo"
                        device = "/dev/sdc1"    # Hint only

                        status = ["ALLOCATABLE"]
                        flags = []
                        dev_size = 10477194     # 4.99592 Gigabytes
                        pe_start = 2048
                        pe_count = 1278 # 4.99219 Gigabytes
                }
        }

I suggest you take a look at the contents of the directory /etc/lvm and the output of the command lvm dumpconfig

Suppose I have machine with 2 disks configured into a logical volume can I just take those disks out the machine and put them in another machine and expect that the logical volume will work in the new machine?

Yes, you can.

You can migrate Volume Groups to another host. Though its not exactly plug-and-play, the procedure to do this is pretty straight-forward. There are dozens of tutorials available online how to do this.

This serverfault thread discusses about moving an LVM partition to another host using the dd command.

14

Does pvcreate /dev/sdb write any metadata to /dev/sdb? if so what is written?

Yes, but it's not much more than some header and identification data to mark the block device as an LVM PV. The "real" metadata comes when you create volume groups.

Where does vgcreate data /dev/sdb /dev/sdc store configuration of the volume group?

On each physical volume that is part of the volume group. By default, an identical copy of the metadata is maintained in every metadata area in every physical volume within the volume group. LVM volume group metadata is small and stored as ASCII.

Where does LVM store the mapping between logical extents and physical extents?

That's part of the aforementioned volume group metadata.

Is there any machine specific configuration in a LVM configuration?

No. PVs that are part of a VG are found and assembled by using unique identifiers assigned at the time of PV creation.

Suppose I have machine with 2 disks configured into a logical volume can I just take those disks out the machine and put them in another machine and expect that the logical volume will work in the new machine?

Yes. If all the PVs that make up the VG are present then the LVs on that VG will work.

3
  • Does pvcreate /dev/sdb write any metadata to /dev/sdb? if so what is written?
  • Where does vgcreate data /dev/sdb /dev/sdc store configuration of the volume group?

pvcreate creates a "label" and a "header" for the PV and also allocates space for metadata on the volume (as specified by the --[pv]metadata option). The header is a binary data structure which includes pointers to the metadata area(s) on that PV.

The vgcreate command stores a textual description of the current state of the volume group into the metadata areas previously allocated on the associated PVs (as controlled by the --[vg]metadatacopies option, etc.). These are the descriptions backed up by the vgcfgbackup command, and in most cases are the metadata that one would be interested in examining.

For the more-obscure PV label/header information: one overview description can be found in LVM Internals, http://mo.morsi.org/blog/node/392 (which includes a link to a Ruby script which can parse the label/header, lvm-parser.rb.)

A similar Python module, pvdissect, is found at the bottom of http://www.syslinux.org/wiki/index.php?title=Development/LVM_support .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.