Logical Volume Manager
lastmod 2018-08-17created 2015-07-0627 edits
Wikimedia_-_Lvm.svg.png
In Linux, the Logical Volume Manager (LVM) is a device mapper target that provides logical volume management for the Linux kernel. Most modern Linux distributions are LVM-aware to the point of being able to have their root file systems on a logical volume.
Heinz Mauelshagen wrote the original LVM code in 1998, taking its primary design guidelines from the HP-UX volume manager.
Category
- CentOS:ResizeLVM: Explains how to resize the /home directory that is set up by default in a CentOS7 minimal install.
About LVM
LVM stands for Logical Volume Manager, and refers to the parts of the kernel and the programs that allow storage devices to be managed more efficiently and flexibly. It was first developed by IBM, then adopted by OSF (now OpenGroup) and used in the OSF/1 operating system. It is now used in commercial Unixes such as HP-UX, the Digital Unix operating system, and AIX. The Linux version is currently being developed as open source by Sistina Software, modeled on the HP-UX one.
To understand LVM, Software RAID (Redundant Array of Inexpensive Drives) must first be mentioned; the two are similar yet differ greatly. What they have in common is that they let multiple physical disks be handled like a single logical disk, achieving high capacity, high speed, and data integrity depending on how they are combined. But there is a clear difference. LVM is relatively easier to manage and extend than RAID, whereas RAID has methods LVM lacks, such as disk mirroring (RAID level 1) and Parity Stripe (RAID level 4,5), which can guarantee speed or data integrity.
Despite these differences, LVM draws attention for the following reasons.
- Easy management.
- Supports combining many different devices.
- Intuitive access to storage devices.
- Excellent scalability.
- Reliable safety and efficiency.
- Snapshot support.
Users gain many benefits from these characteristics.
First, one of the biggest concerns for PC-class system users is probably how to lay out partitions when first installing the system, because partitions are not easy to change once set up. And when a partition fills up, it is not uncommon to have to go through a painful backup or reluctantly (?) delete data. With LVM, however, storage space can be easily extended or shrunk, which eases that concern.
As another example, small and medium servers can build large-capacity storage at relatively low cost. And since they can be extended while keeping the existing environment without a backup (of course, backups are always important), there is a considerable benefit in terms of maintenance.
| Important |
| LVM turns physical volumes into logical ones. In other words, it is not a file system (Filesystem). Simply put, it helps manage hard disk partitions logically and flexibly. |
Terms
- Physical volume (PV; Physical Volume)
- A physical volume generally refers to a hard disk partition or a device that looks similar to a hard disk partition, such as a RAID device.
- Logical volume (LV; Logical Volume)
- Several physical volumes make up a logical volume. In LVM, a logical volume is similar to a hard disk partition on a system that does not use LVM. A logical volume can contain a file system such as /home or /usr.
- Volume group (VG; Volume Group)
- These logical volumes together form a volume group. In LVM, a volume group is similar to a physical hard disk on a system that does not use LVM. A volume group gathers several logical volumes into a single administrative unit.
- Physical extent (PE; Physical Extent)
- A physical volume is divided into basic units called PEs. The size of a physical extent is arbitrary, but it is the same for physical volumes belonging to the same volume group. Within a physical volume, each PE has a unique number. The PE is the smallest unit by which LVM addresses physical storage space.
- Logical extent (LE; Logical Extent)
- Each logical volume is divided into addressable basic units called LEs. Within the same volume group, the size of a logical extent equals the size of a physical extent. Naturally, the LE size of all logical volumes in a volume group is also the same.
- Volume group descriptor area (VGDA; Volume Group Descriptor Area)
- You may be wondering where all the meta information about logical volumes and volume groups is stored. To use an analogy with systems that do not use LVM, partition information is stored in the partition table. In LVM, the volume group descriptor area (VGDA, Volume Group Descriptor Area) serves the same function as the partition table. The VGDA is stored at the beginning of each physical volume. The VGDA contains the following information.
- One PV descriptor
- One VG descriptor
- LV descriptors
- Several PE descriptors.
How LVM works
Each PE has a unique number within a physical volume, but not within a logical volume. This is because a logical volume is made up of several physical volumes, so PE IDs can overlap. Therefore an LE ID is needed to distinguish 'the LE' from 'the PE linked to the LE'. As already mentioned, LEs and PEs map 1:1. The LE ID is used when accessing storage and writing actual data to physical storage space.
When the system boots, the LVs and VGs are activated and the VGDA is read into memory. The VGDA tells where the LVs are actually stored. When the system accesses a storage device, it goes through a mapping process (with the help of the VGDA) to find the physical location for the actual I/O.
Physical disks are partitioned with fdisk, but logical LVM disks are divided with the lvcreate command. (logical volume)
List of command
-
vgs - Report information about volume groups.
-
vgdisplay - Displays volume groups (VG).
-
vgdisplay -v test - Displays detailed information about a volume group (VG). (Above, it displays the
testvolume group.)
-
pvcreate /dev/hda3 - Creates a physical volume (PV) on the partition passed as the argument (
/dev/hda3above).
-
vgcreate test /dev/hdb2 /dev/hda3 - Creates a volume group (VG) and includes the partitions passed as arguments in the group.
-
lvcreate -L 50M -n test-volume test - Creates a logical volume (LV). (Above, it is created in the
testvolume group (VG), with size50M, under the nametest-volume.) - Afterwards, a file system can be assigned to the logical volume (LV). (e.g.
mke2fs {volume_path}) 1
-
lvscan - Scans all disks for logical volumes (LV).
-
lvdisplay - Displays logical volumes (LV).
-
vgextend my_volume_group /dev/hdc1 - Adds the
/dev/hdc1partition to themy_volume_groupvolume group.
Remove example
To tear down LVM, proceed in the reverse order of creation.
Files
-
/etc/lvm/lvm.conf - LVM configuration file. Settings such as filters can be added.
See also
Favorite site
- Wikipedia (en) LVM
- [Recommended] KLDP: Logical Volume Manager HOWTO
- [Recommended] Using the Logical Volume Manager
- Adding a hard disk on Linux / LVM
- Creating and deleting LVM (Logical Volume Manage)
- [Recommended] LVM(Logical Volumn Manager) concepts and settings 2
Manual
- Red Hat Enterprise Linux 6 LVM (Logical Volume Manager) Administration
- Gentoo linux: LVM
- Linux LVM disk management and adding disks