In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to understand the LVM logic volume, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
LVM is a mechanism for managing disk partitions in Linux environment. It is a logical layer built on hard disks and partitions and under the file system, which can improve the flexibility of disk partition management. The default partition format installed by RHEL5 is the format of LVM logical volumes. It is important to note that / boot partitions cannot be created based on LVM and must be independent.
I. LVM principle
In order to understand the principle of LVM, we must first master four basic concepts of logical volumes.
① 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 the disk, we present it to the upper services as logical volumes. So all our operations are actually to create a LV (Logical Volume), where the logical volume is used to replace our previous partition, and we can use it by formatting the logical volume and then mounting it. So how does LVM work? The so-called "no picture, no truth", let's explain the principle of logical volume through the diagram below.
1. Format our physical hard drive to PV (Physical Volume)
We can see that there are two hard drives here, one is sda and the other is sdb. In LVM disk management, I first need to format these two hard drives into our PV (Physical Volume), that is, our physical volumes. In fact, in the process of formatting physical volumes, LVM divides the underlying hard drives into PE (Physical Extend), and 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 drive, when I format it into PV, I actually divide the physical hard drive into 100m PE, because the default size of PE is 4m. This is our first step.
two。 Create a VG (Volume Group)
After formatting the hard disk into PV, our second step is to create a volume group, that is, VG (Volume Group), where we can abstract it into a space pool. The function of VG is to install PE. We can add one or more PV to VG, because the hard disk has been divided into multiple PE in the first step, so after adding multiple PV to VG VG contains a lot of PE from different PV. We can see from the picture above that we formatted two hard drives, each of which was formatted into three PE, and then added the PE of both hard drives to our VG. Then our VG contains six PE, which is the sum of the PE of the two hard drives. Usually when we create a volume group, we give it a name, that is, the name of the VG.
3. Create the final LV (Logical Volume) we are going to use based on VG
[note] after PV and VG are created, we cannot use them directly, because PV and VG are the things at the bottom of our logical volume, and we actually end up using LV (Logical Volume) created on the basis of VG, so the third step is to create the LV we want to use based on VG.
When we have created our VG, when we create the LV, we actually take our specified number of PE from the VG, or take the figure above. We see that we already have six PE in our VG at this time. At this time, we create our first logical volume, which is the size of four PE, that is, 16m (because the default size of a PE is 4m). Three of the four PE are from the first hard drive, while the other PE is from the second hard drive. When we create the second logical volume, it will be at most the size of two PE, because four of the PE have already been assigned to our first logical volume.
So to create a logical volume is to take out our specified number of PE,VG from VG, the PE in our specified number of PE,VG can come from different PV, the size of the logical volume we can create depends on the number of PE in the VG, and the size of the logical volume we create must be an integral multiple of PE (that is, the size of a logical volume must be an integral multiple of 4m).
4. Format the LV we created for the file system, and then mount it for use
After creating the LV, we will be able to format the file system. What we finally use is the LV we just created, which is equivalent to the traditional file management partition. We have to format it first, and then mount it through the mount command. At this time, we will be able to use our logical volumes as if we were using normal partitions.
After we have created 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 folder named with the VG name in the / dev directory. After creating the LV based on the VG, we will add a logical volume named with the LV name in this VG directory.
Let's summarize how the whole LVM works:
(1) physical disks are formatted as PV, and space is divided into PE.
(2) different PV is added to the same VG, and all the PE of different PV are added to the PE pool of VG.
(3) LV is created based on PE and its size is an integral multiple of PE. The PE that makes up LV may come from different physical disks.
(4) LV can be directly formatted and mounted.
(5) the expansion and reduction of LV actually increases or decreases the number of PE that make up the LV, and the process does not lose the original data.
We see that if we want to expand the LV here, add a sdc hard drive directly, then format it into PE, and then add the PV to the VG. At this time, we can dynamically expand the LV by increasing the number of PE in the LV, as long as the size of our LV does not exceed the size of our VG free space.
Second, create LVM logical volume
Familiar with how LVM works, the first step is to format our physical hard disk into PV, then add multiple PV to the created VG, and finally create our LV through VG.
Third, stretch a logical volume
We know that compared to the problems of traditional disk management, using LVM logical volumes to manage our disks, we can manage them dynamically. In the traditional disk management, if we have insufficient partition size, we can only add a physical hard disk and then partition it, because the added hard disk exists as an independent file system, so it has no effect on the original partition. If we need to expand the partition at this time, we can only unmount the previous partition first, and then transfer all the information to the new partition. Finally, mount the new partition, which is very troublesome if it is in a production environment. Because of this, we have the disk management mode of LVM, which can manage our disks dynamically.
Let's first look at the schematic diagram of dynamically stretching a logical volume:
As we can see from the figure above, when we stretch the logical volume, the essence is to increase the number of PE to the logical volume, and the number of PE is determined by the number of PE left in the VG.
[note:] the stretching operation of logical volumes can be carried out online, and there is no need to unmount our logical volumes
The advantage is that when the size of our logical volume is not enough, we do not need to uninstall it, we can dynamically increase the size of our logical volume and will not have any impact on our system. For example, if we have an important service or database running on our server and require us to stay online 24 hours a day, it is necessary to dynamically increase the size of logical volumes.
Next, let's look at the steps to stretch a logical volume:
Because the stretching operation of our logical volume can be carried out online, here we mount the logical volume first and stretch our logical volume dynamically in use.
The above is how to understand LVM logic volumes. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.