Development/LVM support

From Syslinux Wiki
Jump to: navigation, search

Introduction

It is clarifying to look at LVM support from two angles:

  • LVM support in ldlinux.sys
  • LVM support in EXTLINUX

LVM support in ldlinux.sys

Very broadly speaking this means that ldlinux.sys should learn to access files from filesystems installed in an LVM logical volume. It would need to know how to translate the access of all "blocks" of that filesystem to the corresponding "blocks" of the LVM physical volume involved (ie, know which sectors should be read from disk to retrieve the contents of a file stored in a filesystem that is installed in an LVM logical volume).

LVM support in EXTLINUX

Syslinux should allow installation to a filesystem installed in an LVM logical volume. (It seems that EXTLINUX is the best binary to use for that.)

Roughly sketched, that could be done like this:

  • EXTLINUX should detect whether it is asked to install ldlinux.sys into a directory of a filesystem that resides on an LVM logical volume;
  • if that is the case, it needs to find out which LVM volume group that LVM logical volume belongs to and then find out which LVM physical volumes are used to store that LVM logical volume;
  • knowing which LVM physical volumes are used, ldlinux.sys should be written to one (or all) of these LVM physical volumes;
  • writing the EXTLINUX boot sector into these LVM physical volumes should be straightforward;
  • ldlinux.sys should be written into a physical volume's bootloader area. (It seems there's no way to add a bootloader area to an already existing physical volume. Neither can one change an already existing bootloader area. So EXTLINUX requires a properly created physical volume);
  • the EXTLINUX boot sector should point to that bootloader area. The UUID of the LVM logical volume that holds the filesystem, and the path of the working directory on that filesystem (if not its root), should be saved in ldlinux.sys (perhaps in its ADV).
  • ldlinux.sys should parse the LVM's phyiscal volume's metadata for an LVM logical volume with a matching UUID. If a LVM logical volume with a matching UUID is found in the metadata, ldlinux.sys should have all information needed to map the sectors of the filesystem to physical sectors. That enables it to open the specified working directory, load syslinux.cfg, and proceed as it does on non-LVM based filesystems.

Some pointers to syslinux mailing list messages and threads

Linux syslinux-3.72 does not update boot block for SD devices [1] (October 2008)

LVM support [2] (April 2009)

Linux software RAID 1.2 superblocks [3] (June 2010)

LVM2 information

LVM2 Resource Page

LVM2 added support for bootloader areas: WHATS_NEW for version 2.02.99

LVM2 physical volumes disk layout

The disk layout of LVM2 physical volumes is not (informally) described somewhere. (The code for reading and writing those volumes is open of course).

I've written a small python module to dissect (ie, parse the layout end then print offsets, descriptions and values) these physical volumes. This can help in understanding the on disk structure of LVM2's physical volumes. Sample output (edited):

0x00000200 (label_header.id):
    LABELONE
0x00000208 (label_header.sector):
    1
0x00000210 (label_header.crc):
    0xceb77890
0x00000214 (label_header.offset):
    0x20              
0x00000218 (label_header.type):
    LVM2 001
0x00000220 (pv_header.uuid):
    iiIaVm-EIvw-81oF-ylkq-lHpn-7CZ6-3J5bz9
0x00000240 (pv_header.device_size):
    0x40000000        
0x00000248 (pv_header.disk_areas.da0.offset):
    0x100000          
0x00000250 (pv_header.disk_areas.da0.size):
    0x0               
0x00000268 (pv_header.disk_areas.mda0.offset):
    0x1000            
0x00000270 (pv_header.disk_areas.mda0.size):
    0xff000           
0x00001000 (mda_header.checksum):
    0x3208e51b
0x00001004 (mda_header.magic):
     LVM2 x[5A%r0N*>
0x00001014 (mda_header.version):
    1
0x00001018 (mda_header.start):
    0x1000            
0x00001020 (mda_header.size):
    0xff000           
0x00001028 (mda_header.raw_locns0.offset):
    0x600             
0x00001030 (mda_header.raw_locns0.size):
    0x360             
0x00001038 (mda_header.raw_locns0.checksum):
    0x82217a88
0x0000103c (mda_header.raw_locns0.flags):
    0
0x00001600 (metadata.value):
    vg_test {
        [...]
        
        physical_volumes {
            
            pv0 {
                [...]
            }
            
            pv1 {
                [...]
            }
        }
        
    }
    [...]

That script can be found at pvdissect.