Basic theoretical knowledge of LVM partition

LVM是Linux环境中对磁盘分区进行管理的一种机制,是建立在硬盘和分区之上、文件系统之下的一个逻辑层,可提高磁盘分区管理的灵活性。**需要注意的是/boot分区不能基于LVM创建,必须独立出来。**

1. LVM principle

To understand the principles of LVM, we must first grasp the four basic logical volume concepts.

①PE (Physical Extend) physical extension

②PV (Physical Volume) physical volume

③VG (Volume Group) volume group

④LV (Logical Volume) logical volume

We know that after using LVM to dynamically manage disks, we present them to the upper-layer services in the form of logical volumes.

1. Format our physical hard disk into PV (Physical Volume)

There are two hard disks, one is sda and the other is sdb. In LVM disk management, I first need to format these two hard disks as our PV (Physical Volume), which is our physical volume. In fact, format the physical In the volume process, LVM divides the underlying hard disks into one PE (Physical Extend). The default size of PE in our LVM disk management is 4M. In fact, PE is the most basic unit of our logical volume management. For example, if I have a 400M hard disk, when formatting it into PV, it actually divides this physical hard disk into 100 PEs, because the default size of PE is 4M. This is our first step.

2. Create a VG (Volume Group)

After formatting the hard disk into PV, our second operation is to create a volume group, which is VG (Volume Group), where we can abstract the volume group into a space pool. The role of VG is to install PE , We can add one or more PVs to the VG, because the hard disk has been divided into multiple PEs in the first step of operation, so after adding multiple PVs to the VG, the VG will store many Many PEs from different PVs, as we can see from the picture above, we formatted two hard drives, each hard drive was formatted into 3 PEs, and then the PEs of the two hard drives were added to our In the VG, then our VG contains 6 PEs, and these 6 PEs are the sum of the PEs of the two hard drives. When creating a volume group, we usually give it a name, which is the name of the VG.

3. Create the last LV (Logical Volume) we will use based on VG

[Note] After the PV and VG are created, we cannot use them directly, because PV and VG are the underlying things of our logical volume. In fact, we finally use the LV (Logical Volume) created on the basis of VG, so the third The step operation is based on VG to create the LV we will eventually use.

After we create our VG, at this time we create LV actually take out the number of PEs we specify from the VG, or take the picture above, we can see that we already have 6 PEs in the VG at this time. At this time we created our first logical volume, its size is the size of 4 PEs, which is 16M (because the default size of a PE is 4M), and three of these 4 PEs are from the first block Hard disk, and the other PE comes from the second hard disk. When we create the second logical volume, its size is only the size of two PEs at most, because 4 of them have been allocated to our first logical volume.

So creating a logical volume is actually when we take out the number of PEs we specify from the VG. The PEs in the VG can come from different PVs. The size of the logical volume we can create depends on the number of PEs in the VG, and the logic we create The size of the volume must be an integer multiple of PE (that is, the size of the logical volume must be an integer multiple of 4M).

4. Format the file system of the LV we created, and then mount it for use

After the LV is created, we can format the file system at this time. What we finally use is the LV that we just created, which is equivalent to the traditional file management partition. Format the file system, and then mount it through the mount command. At this time, we can use our logical volume like a normal partition.

After we create the LV, we will see our LV information in the /dev directory, for example, /dev/vgname/lvname. Every time we create a VG, it will create a VG named after the VG in the /dev directory Folder, after the LV is created on the basis of the VG, we will add a logical volume named LV under the VG directory.

Let's summarize the working principle of the entire LVM:

(1) The physical disk is formatted as PV, and the space is divided into individual PEs

(2) Different PVs are added to the same VG, and the PEs of different PVs all enter the PE pool of the VG

(3) LV is created based on PE, the size is an integer multiple of PE, the PE that composes LV may come from different physical disks

(4) LV can be formatted and mounted directly

(5) The expansion and reduction of LV is actually to increase or decrease the number of PEs that make up the LV, and the process will not lose the original data

Guess you like

Origin blog.csdn.net/smileui/article/details/96847141