LVM stands for Logical Volume Manager, it provides a method of allocating space on mass storage devices. Its main characteristic and strengtht is that it is more flexible than conventional partitioning schemes.
LVM is such a big subjetc that there is a redbook only for that. So, I will try to explain the main concepts and some of the most useful commands.
From top to bottom we are going to talk about Physical Volumes, Volume Groups, Logical Volumes and ODM.
Physical Volumes (PV)
They can be hard disks, hard disk partitions or LUNs from a external storage. They can start to be called PVs when they are given "format" with the following command.
The physical volume is partitioned into contiguous, equal sized units of
space called physical partitions (PP). PP is the smallest unit of
storage space allocated.
chdev -l hdiskx -a pv=yes
This command creates an identifier that is called physical volume identifier (PVID) and it is written on the first block of the device and in the ODM.
PVID is a combination of the machine’s serial number (from the systems EPROMs) and the date the PVID was generated. It can be seen with different commands:
# lspv hdiskpower15 |grep -i pv
PV IDENTIFIER: 00cab1c214dc6ea1 VG IDENTIFIER 00cab1c200004c000000013388c518cd
PV STATE: active
# lsattr -EHl hdiskpower15|grep pvid
pvid 00cab1c214dc6ea10000000000000000 Physical volume identifier False
pvid_takeover yes Takeover PVIDs from hdisks True
# lquerypv -H /dev/hdiskpower15
00cab1c214dc6ea10000000000000000
The first 128 sectors of a physical volume are reserved to store various types of information like the boot record (sector 0) , the mirror write consistency (MWC) record (sector 1) or LVM record (sector 7) among others. Sector 128 is the first non reserved one, the volume group descriptor area and status area (VGDA / VGSA) record starts here. There is another reserved area at the end of the disk, and it is reserved as a
relocation pool for bad blocks.
Volume Group (VG)
It is a collection of physical volumes, this is the definition from Redbook. I would add that VG is composed by at least one PV and it is divided into different Logical Volumes.
When you install the system a VG is created (rootvg). You can create new VG with command mkvg, and using the extendvg command you can add PV to a VG and can be removed using the reducevg command.
Depending on the maximum numbers of PVs and LVs that VGs can contain, they can be Normal (32 PVs), Big (128 PVs) and Scalable (1024 PVs).
You can check this with command readvgda
# readvgda hdiskpower21 |grep type
..... readvgda_type: smallvg
When a volume group is created, there are a number of operations that runs in the background. A Volume Group Identifier (VGID), VGSA and VGDA areas are created. And two files are created in /dev with the selected major number:
__vgnn where nn is the major number (Note: NFS uses the major number as part of the file handle)vg_name
# ls -l /dev/*vg* |grep 38
crw------- 1 root system 38, 0 Jun 03 08:21 /dev/__vg38
crw-rw---- 1 root system 38, 0 Jun 03 08:21 /dev/sapvg
VGID is and identifier as the PVID
VGSA contains the state of all allocated PPs on all of the PVs in the VG. It contains information about the VG factor and the Physical volume missing flag.
What is the factor? The factor determines the maximum number of PVs and PPs per PV that a VG can have.
By default, the number of physical partitions factor is
set to 1, this means that one VG can have 1016 PPs per PV and 32 PVs as
maximum.
This can be changed with the following command chvg -t factor .
VGDA resides on the edge of the disk and it requires
contiguous space in case of VGDA expansion. It contains information about the volume group, the logical volumes that reside in the volume group, and the physical volumes that make up the volume group.
The VGDA is updated by almost all the LVM commands related to a VG; for instance create or extend a logical volume, add a new physical volume. This involves that the VGDA on all disks is updated.
VGDA is divided into the following:
- list of logical volume entries.
- list of physical volume entries.
- volume group header.
- volume group trailer.
Every physical volume has two VGDAs, if there is one PV in the VG, both copies og VGDA are used.
If there are two physical volumes, both copies are used in the first physical volume and just the first copy in the second physical volume.
If there are three or more physical volumes, only the first copy is used in each physical volume.
Logical Volume (LV)
It is a portion of a physical volume or volumes viewed by the system as a single unit. Logical volumes can only exist within one volume group.
There are two elements to take into account: - The logical volume identifier (LVID) is the soft serial number, this number also represents the order in which the logical volume was created within the volume group.
- The logical volume control block (LVCB), The LVCB holds important information, such as the creation date of the logical volume, information about mirrored copies and mount points.
Logical volumes are divided into logical partitions; these logical partitions are how logical volumes handle both the mapping to physical partitions on one or more physical volumes and multiple copies for mirroring. The command reorgvg which rearranges the physical partitions within the volume group, this means that the mapping between the logical partitions and the physical partitions is changed.
I will finish with a couple of remarks about the ODM and LVM
The information that is contained in the VGDA and LVCB is also stored on the system, this information is kept in the object data manager (ODM) and also there are some files in /etc which hold information.
That information in the ODM is stored in stanzas, under /etc/objrepos, /usr/lib/objrepos and /usr/share/lib/objrepos. You can find several files where that information is stored, CuAt,CuDv, PdAt, PdDv,...
You can query the information stored in those files with command odmget
odmget -q name=LV CuAt
If you are interested in this topic and want to go into detail about it, you can check the last link below in the references area.
There are commands which implies LVM modification, then a lock is put in the vg entry in the ODM.
The user can unlock the vg in two ways:
putlvodm -K <VGID>
varyonvg the volume group
putlvodm -K <VGID>
varyonvg the volume group
References
LVM Redbook
Decoding PVID
VG Management
ODM