Lvm
LVM is shorthand for Logical Volume Manager (Logical Volume management), a mechanism for managing disk partitions in a Linux environment, implemented by Heinz Mauelshagen on the Linux 2.4 kernel, Currently the latest version is: Stable version of 1.0.5, development version of 1.1.0-RC2, and LVM2 development.
Directory
1, overview
2, preface
3, Basic terminology
4, summary
5, advantages
6, Related concepts
7,LVM's management tools
8, working style
Overview:
LVM is the abbreviation for Logical Disk volume management (Logical Volume Manager), which is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer on top of hard disks and partitions to improve the flexibility of the management of the disk sub-LVM zone. As mentioned earlier, LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume. Physical volume (physical volume) physical volume refers to a hard disk partition or a device that logically shares the same functionality as a disk partition (such as RAID), which is the basic storage logic block of LVM, but is compared to the basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM.
One of the most common and difficult questions that Linux users encounter when installing Linux operating systems is how to properly evaluate the size of each partition to allocate the appropriate hard disk space. When a partition is exhausted, the solution is usually to use symbolic links, or to use tools that resize the partition (such as patitionmagic, etc.), but this is only a temporary workaround and does not solve the problem at all. With the advent of Linux's logical volume management capabilities, these problems are solved, allowing users to easily adjust the size of each partition without the need for downtime.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/39/62/wKioL1O6CPmzjXxSAAGO7ZyW74A500.jpg "title=" Qq20140707103708.png "alt=" Wkiol1o6cpmzjxxsaago7zyw74a500.jpg "/>
Objective:
Each Linux consumer will encounter this dilemma when installing Linux: How to accurately evaluate and allocate the capacity of each hard disk partition when partitioning the system, as the system administrator takes into account not only the capacity required for a current partition, but also the maximum capacity that may be required for that partition. Because if the estimate is inaccurate, the administrator may even want to back up the entire system, clear the hard disk, re-partition the hard disk, and then restore the data to the new partition when a partition is not sufficient.
While there are a lot of dynamic disk-tuning tools available, such as partationmagic and so on, it does not solve the problem completely, because one partition may be exhausted again, another is the need to reboot the system to achieve, for many critical servers, downtime is unacceptable, And for adding a new hard disk, if you want a file system that spans multiple hard drives, the partition tuning program does not solve the problem.
Therefore, the perfect solution should be in the 0 downtime under the premise of the size of the file system can be easily adjusted to facilitate the implementation of the file system across different disks and partitions. Fortunately, the Logical Disk volume management (lvm,logicalvolumemanager) mechanism provided by Linux is a perfect solution.
LVM is the abbreviation for Logical Disk volume management (logicalvolumemanager), which is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management. The LVM system administrator makes it easy to manage disk partitions, such as connecting several disk partitions to a single block of volume group (volumegroup), forming a storage pool. Administrators can create logical volume groups (logicalvolumes) at will on a volume group and further create file systems on logical volume groups. The administrator can easily adjust the size of the storage volume group through LVM, and the disk storage can be named, managed and assigned as a group, for example, "development" and "sales", instead of using the physical disk name "SDA" and "SDB". And when a new disk is added to the system, the LVM administrator does not have to move the disk's files to the new disk to take full advantage of the new storage space, but instead directly extend the file system across the disk.
Basic terminology:
As mentioned earlier, LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume. First we discuss the following LVM terminology:
* Physical storage media (the physical media)
This refers to the system's storage device: The hard disk, which is the storage unit at the lowest level of the storage system.
* Physical Volume (physical VOLUME,PV)
A physical volume is a partition of a hard disk or a device that logically has the same function as a disk partition (for example, RAID), which is the basic storage logic block of LVM, but is compared to basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM.
* Volume group (Volume GROUP,VG)
LVM volume groups are similar to physical hard disks in non-LVM systems, which consist of physical volumes. You can create one or more LVM partitions (logical volumes) on a volume group, and an LVM volume group consists of one or more physical volumes.
* Logical Volume (logical VOLUME,LV)
LVM logical volumes are similar to hard disk partitions in non-LVM systems, and file systems (such as/home or/usr) can be created on top of logical volumes.
*pe (physical Extent,pe)
Each physical volume is divided into a basic unit called PE (physicalextents), 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.
*le (Logical Extent,le)
Logical volumes are also divided into addressable basic units called LE (logicalextents). In the same volume group, the size of Le is the same as the PE, and one by one corresponds.
The first thing you can see is that the physical volume (PV) is made up of basic unit PE of equal size.
A volume group consists of one or more physical volumes.
As you can see, PE and Le have one by one corresponding relationships. The logical volume is built on the volume group. A logical volume is equivalent to a non-LVM system disk partition on which a file system can be created.
is a logical relationship between a disk partition, a volume group, a logical volume, and a file system:
and non-LVM systems The metadata that contains the partition information is saved in the partition table at the beginning of the partition, and the metadata related to the logical volume and volume group is also stored in the Vgda (Volume Group descriptor area) at the beginning of the physical volume. Vgda includes the following: PV descriptors, VG descriptors, LV descriptors, and some PE descriptors.
When the system initiates LVM, the VG is activated and the Vgda is loaded into memory to identify the actual physical storage location of the LV. When the system does an I/O operation, the actual physical location is accessed based on the mapping mechanism established by VGDA.
Summary:
As you can see from the above discussion, LVM is very scalable and easy to use. You can easily adjust the size of the volume group, the logical volume, and further adjust the size of the file system.
Advantages:
M is typically used for systems with large numbers of disks, but it is also suitable for small systems with only one or two hard disks.
Benefits of using LVM with small systems
The traditional file system is partition-based and a file system corresponds to a partition. This method is more intuitive, but not easy to change:
1. The different partitions are relatively independent and not interrelated, and the space is not fully utilized because of the imbalance in the space of each partition;
2. When a file system/partition is full, it cannot be expanded, it can only be used to repartition/build the file system, it is cumbersome, or the data in the partition is moved to another larger partition, or the space of other partitions is used in symbolic connection mode.
3. If you want to combine multiple partitions on the hard disk, you can only use the re-partitioning method, this process requires data backup and recovery. When using LVM, the situation is different:
1. The multiple partitions of the hard disk are managed by the LVM Unified for the volume group, can easily join or remove the partition to enlarge or reduce the volume group's usable capacity, make full use of the hard disk space;
2. The file system is built on a logical volume, and the logical volume can vary in size (within the volume group capacity) as needed to meet the requirements;
3. File system based on LVM, can be cross-partitioned, easy to use;
Benefits of using LVM with large systems
In large systems with many hard drives, the use of LVM is primarily convenient for management and increases the scalability of the system.
In a large-scale system with many different capacity drives, the spatial allocation of different users is a tricky task, which seeks to balance the user's needs with the actual available space.
The user/user group space is built on the LVM and can be increased at any time, or adjusted for each logical volume according to usage. When the system is running out of space and adding a new hard disk, it is not necessary to migrate the user's data from the original to the new hard disk, but only to add the new partition to the volume group and expand the logical volume. Similarly, using LVM can be a non-stop service scenario. Transfer user data from the old hard drive to the new hard disk space.
Related concepts:
Physical volume
A physical volume is a hard disk partition or a device (such as a RAID device) that logically looks similar to a hard disk partition.
Logical volumes
One or more physical volumes compose a logical volume. For LVM, logical volumes are similar to hard disk partitions in non-LVM systems. A logical volume can contain a file system (such as/home or/usr).
Volume Group
One or more logical volumes compose a volume group. For LVM, a volume group is similar to a physical hard disk in a non-LVM system. A volume group combines multiple logical volumes to form a manageable unit.
Physical Block physical extent (PE)
Physical volumes are stored in units of equal size, and the size of the block is the same as the size of the logical volume block in the volume group.
Logic Block logical extent (LE)
Logical volumes are stored in "blocks", and the block size of all logical volumes in a volume group is the same.
Working mode:
Let's take a look at how LVM works. Each physical volume is divided into several basic units, the so-called PE (physical extents). The size of the PE is variable, but must be the same as the physical volume of the volume group to which it belongs. In each physical volume, each PE has a unique number. PE is the smallest unit in a physical storage that can be addressed by LVM.
Each logical volume is also divided into a number of basic units that can be addressed, called LE (Logical extents). In the same volume group, le is the same size as PE, and it is clear that the size of Le is the same for all logical volumes in a volume group.
In a physical volume, each PE has a unique number, but this is not necessarily necessary for logical volumes. This is because when these peid numbers are not available, the logical volumes can consist of some physical volumes. Therefore, the Le ID number is used to identify LE and the specific PE associated with it. Each time the storage area is addressed or the ID of Le is used, the data is written on top of the physical storage device.
You might find it strange that all the metadata about logical volumes and logical volume groups is stored. Similarly, in non-LVM systems, data about partitions is stored in partitioned tables, and partitioned tables are stored in the starting position of each physical volume. The VGDA (Volume Group descriptor area) function is like an LVM partition table, which is stored at the beginning of each physical volume.
The VGDA consists of the following information:
A PV descriptor
A VG Descriptor
LV Descriptor
Some PE descriptors
When the system starts the LV, the VG is activated and the Vgda is loaded into memory. Vgda helps identify the actual storage location of the LV. When the system wants to access the storage device, the mapping mechanism established by VGDA is used to access the actual physical location to perform I/O operations.
Management tools for LVM:
Feature Management physical Volume Management Volume Group Management Logical Volume
Scan scanning pvscan vgscan Lvscan
Create pvcreate vgcreate lvcreate
Display displays pvdisplay vgdisplay lvdisplay
Remove delete pvremove vgremove lvremove
Extend extension vgextend lvextend
Reduce vgreduce lvreduce
----Graphics management tools :
[Email protected] ~]# SYSTEM-CONFIG-LVM
Note: If you do not have this command, we can put the relevant software packaging, we can use "RPM" or "yum" way to install. I installed it in a "yum" way. That's the package that will produce this package. See below:
[Email protected] ~]# RPM-QF/USR/SBIN/SYSTEM-CONFIG-LVM
System-config-lvm-1.1.5-13.el5
[Email protected] ~]# yum-y Install SYSTEM-CONFIG-LVM
Syntax for the main command:
- pvcreate device name ...
- vgcreate Volume Group name physical volume ...
- vgcreate-s PE size Volume group name physical volume ...
- lvcreate-L size-N Logical Volume name volume group name
- lvcreate-l PE number-N Logical Volume name volume group name
- lvextend-L + size/dev/Volume group name/logical volume name
Implementation method:
Note: the partition "/DEV/SDB7" is my new partition. When you are doing it, you can do it according to your own district.
The command to create the physical volume is pvcreate
[Email protected] ~]# pvcreate/dev/sdb7
Writing physical volume data to disk "/dev/sdb7"
Physical volume "/dev/sdb7" successfully created
The above command initializes "/dev/sdb7" to a physical volume, and the physical volume is used to display the command "pvdisplay" To view the physical volume as follows:
[Email protected] ~]# pvdisplay
"/dev/sdb7" is a new physical volume of "9.32 GB"
---NEW physical volume---
PV Name /dev/sdb7
VG Name
PV Size 9.32 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID wsaysw-z57t-36hy-riq7-p8u3-e2gg-dd7i1c
Create Volume Group VG (Volume Groups)
A volume group (Volume Group) is referred to as a VG, which is a combination of one or more physical volumes. A volume group combines multiple physical volumes together to form a manageable unit that resembles a physical hard disk in a non-LVM system.
The command to create a volume group is vgcreate, which is used to create a volume group named "Vg_long" that contains the physical volume "/dev/sdb7".
[Email protected] ~]# vgcreate vg_long/dev/sdb7
Volume Group "Vg_long" successfully created
Use the Volume Group View command Vgdisplay to display the volume group condition:
[Email protected] ~]# vgdisplay
---Volume Group---
VG Name Vg_long
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access Read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
ACT PV 1
VG Size 9.32 GB
PE Size 4.00 MB
Total PE 2386
Alloc pe/size 0/0
Free Pe/size 2386/9.32 GB
VG UUID mop7ex-6ymh-3jvz-jxrd-smkl-5g14-mvf2e1
Create a logical Volume LV (Logical Volumes)
A logical volume (Logical Volumes), or LV, is a logical area divided into a volume group, similar to a hard disk partition in a non-LVM system.
The command to create the logical volume is "lv_long", with the following command, we created a logical volume named "Lv_long" on the volume Group "Vg_long" with a size of 10GB and the device entry as " /dev/vg_long/lv_long".
[Email protected] ~]# lvcreate-l 8g-n lv_long vg_long
Logical volume "lv_long" created
[Email protected] ~]# lvdisplay
---Logical volume---
LV Name /dev/vg_long/lv_long
VG Name Vg_long
LV UUID t0chyk-vkde-qweq-fhfn-wh0j-uua8-gdneof
LV Write Access Read/write
LV Status Available
# Open 0
LV Size 8.00 GB
Current LE 2048
Segments 1
Allocation inherit
Read ahead Sectors Auto
-Currently set to 256
Block Device 253:0
You can also use the "-l" parameter to set the logical partition size by specifying the number of PE.
To create a file system:
To create the ext3 file system on a logical Volume:
[Email protected] ~]# mkfs.ext3/dev/vg_long/lv_long
Once the file system has been created, it can be loaded and used:
We mount our new "logical volume" to the "/mnt" directory. This directory is used to mount some partitions.
[Email protected] ~]# mount/dev/vg_long/lv_long/mnt/
This article is from the "Dragon" blog, make sure to keep this source http://1208073155.blog.51cto.com/9039381/1435230