Linux LVM Logical Volume Management Details

  

This article introduces the concept, role, and usage of LVM to help you understand LVM and to use LVM to manage your disk systems flexibly.
1. What is LVM

1.1 LVM Concept
LVM is short for Logical Volume Manager, which is a kind of management for disk partitioning. Mechanism, built on a logical layer above the hard disk and partition, to improve the flexibility of disk management. LVM can connect several disk partitions into a single volume group (Volume Group) to form a storage pool. You can create logical volumes (Logical Volumes) on the volume group and further create a file system on the logical volume, providing more flexibility than using physical storage directly for management. LVM is essentially a virtual device driver that sits between the physical device and the file system layer, maintaining a mapping between logical extents and physical extents. It combines several disks or partitions to form a storage pool or volume group. LVM divides logical volumes of different sizes from the volume group to create new logical devices. Figure 1 is a graphical representation of the LVM structure simulation. Figure 1 LVM structure diagram 1.2 LVM advantages
LVM will store virtualization, using logical volumes, you are not limited by the size of the physical disk, in addition, the hardware-related storage settings are hidden, you can You don't have to stop applying or unmounting file systems to adjust volume size or data migration. This can reduce operating costs. LVM has the following advantages over direct use of physical storage: 1. Flexible capacity When using logical volumes, the file system can be extended to multiple disks, and you can aggregate multiple disks or partition the disk into a single logical volume. 2. Scalable Storage Pools You can use simple commands to expand or shrink logical volume sizes without reformatting or partitioning disk devices. 3. Online data redistribution You can move data online, and data can be redistributed while the disk is online. For example, you can replace a hot-swappable disk online. 4. Convenient device naming logical volumes can be named any name that you find convenient. 5. Disk sharding You can generate a logical disk whose data can be stored in two or more disks. This can significantly improve data throughput. 6. Mirrored Volumes LVM logical volumes provide a convenient way to mirror your data. 7. Volume Snapshots Using logical volumes, you can get device snapshots for consistent backups or test data updates without affecting real data. Second, the role of LVM

The size of the storage volume can be easily adjusted online by LVM, and the disk storage can be named, managed and distributed according to the group, for example, according to the purpose of use: "&ldquo ;development” and “sales” instead of using the physical disk name <;sda” and “sdb”. When a new disk is added to the system, LVM can directly extend the file system across the disk without having to move the file to the new disk. In addition, the LVM snapshot function and the LVM mirroring function are also commonly used in data backup and recovery systems. Three, LVM related basic concepts

Figure 2 PV, VG, LV relationship 3.1 Physical storage media (The physical media)
This refers to the system storage device: hard disk, such as: /dev/hda1, /dev/sda, etc., are the storage units at the lowest level of the storage system. 3.2 Physical Volume
Physical volume refers to a hard disk partition or a device (such as RAID) that logically has the same function as a disk partition. It is the basic storage logical block of LVM, but with basic physical storage. Media (such as partitions, disks, etc.) are compared, but contain management parameters related to LVM. 3.3 Volume Group
Volume groups consist of physical volumes, similar to physical hard disks in non-LVM systems, you can create one or more "LVM partitions" (logical volumes) on the volume group . 3.4 Logical Volumes
LVM logical volumes are similar to hard disk partitions in non-LVM systems. File systems can be created on top of logical volumes (such as /home or /usr). Linear Volumes A linear logical volume aggregates multiple physical volumes into one logical volume. For example, if you have two 60GB hard drives, you can generate 120GB logical volumes. 3.5 chunked logical volumes ( Striped Logical Volumes)
When you write data to this logical volume, the file system can place data into multiple physical volumes. For a large number of connection read and write operations, it can improve data I/O efficiency. 3.6 Mirrored Logical Volumes
Mirrors store consistent data on different devices. Data is written to both the original device and the mirror device. It provides fault tolerance between devices. 3.7 Snapshot Volumes
A snapshot volume provides a device virtual image at a specific instant. When the snapshot starts, it copies a change to the current data region, since it prioritizes these changes, so it The state of the current device can be reconstructed. 3.8 PE (Physical Extent)
Each physical volume is divided into basic units called PE (Physical Extents), and a uniquely numbered PE is the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB. 3.9 LE (Logical Extent)
Logical volumes are also divided into basic units that can be addressed, called LE (Logical Extents). In the same volume group, the size of the LE and the PE are the same, and one-to-one correspondence. 3.10 VGDA (Volume Group Descriptor Area)
The non-LVM system saves the metadata containing the partition information in the partition table at the beginning of the partition, and the logical volume and volume group related metadata are also Saved in the VGDA (Volume Group Descriptor Area) at the beginning of the physical volume. The VGDA includes the following: PV descriptors, VG descriptors, LV descriptors, and some PE descriptors. The system activates the VG when the LVM is started and loads the VGDA into memory to identify the actual physical storage location of the LV. When the system performs I/O operations, the actual physical location is accessed according to the mapping mechanism established by the VGDA. Fourth, install LVM

First, please make sure that the kernel supports LVM. The Turbolinux distribution kernels already support LVM. If your kernel does not support LVM, you can manually compile the kernel. When configuring the kernel, go to the Multi-device Support (RAID and LVM) submenu and check the following options: [*] Multiple devices driver support (RAID and LVM) and then restart Compile the kernel to add support for LVM to the new kernel. Determine if the lvm tool is installed on your system: # rpm -qa |  Grep lvm lvm2-2.02.16-3 If the command result is similar to the above example, the system has already installed the LVM management tool; if the command has no output, it means that the LVM management tool is not installed, you need to download the LVM rpm tool from the network or from the CD. package. In order to use LVM, to ensure that LVM is activated at system startup, the Turbolinux distribution has support for activating LVM at startup, with the following in /etc/rc.d/rc.sysinit: if [ -x /sbin/Lvm.static ]; then action $"Setting up Logical Volume Management:" /sbin/lvm.static vgchange -ay –ignorelockingfailure fiUnder ubuntu, you can use the following command to install LVM2: sudo apt-get install lvm5, create and manage LVM

To create an LVM system, generally need to go through the following steps, as shown in Figure 3: 1) convert the disk to a Linux partition through the fdisk tool; 2) use the pvcreate command to linux The partition is converted into a physical volume (PV); 3) the created physical volume is processed into a volume group (VG) by the vgcreate command; 4) the volume is grouped into several logical volumes (LV) by the lvcreate command; 5) the logical volume is Format, mount, dynamically resize the logical volume, and the operation does not affect the data on the logical volume (Lv). Figure 3 LVM creation flow chart The specific steps of the operation command are described in detail below.

Copyright © Windows knowledge All Rights Reserved