In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the basic concept of LVM logical volume in Linux disk management and what is the working principle of LVM. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
The basic concept of LVM logical volume in Linux disk management mechanism and how LVM works!
I. traditional disk management
In fact, in the Linux operating system, our disk management mechanism is similar to that on windows. Most of them use MBR (Master Boot Recorder) by partitioning a hard disk first, and then formatting the partition into the file system. In the Linux system, if you want to use this partition, you can mount it. In fact, the bottom layer of windows is to mount all the partitions automatically. Then we can use the partition.
But this traditional disk management often brings a lot of problems, for example, when we use a partition, its space size is no longer enough, at this time we have no way to expand the partition by stretching the partition. Of course, there are other third-party disk management software that can partition the disk space, but this will do great harm to our file system. Sometimes it can lead to problems such as file system crashes. For traditional disk management, if we encounter that when the partition size is insufficient, we can only add a new hard disk, then create a partition on the new hard disk, format the partition, and then copy everything from the previous partition to the new partition. However, the newly added hard disk exists as an independent file system, the original file system has not been expanded, and the upper application can only access one file system. This approach may be acceptable for personal computers, but it is unacceptable for servers in production environments. Because if you want to copy all the contents of one partition to another, you must first unmount the previous partition, and then * copy the entire partition. If there is an important service running on the server, such as WWW or FTP, which is running normally 24 hours a day, it is unimaginable to unmount the partition. At the same time, if the partition holds a lot of content. Then it may take a long time to transfer the partition, so at this time we will be limited by the traditional disk management because it can not carry out dynamic disk management. Therefore, in order to solve this problem, LVM technology was born!
II. Disk management of LVM
It is precisely because the traditional disk management can not dynamically manage our disk space, so the birth of the LVM technology, so what is LVM? How does it manage disks?
LVM (Logical volume Manager) is short for logical volume management. It is a mechanism for managing disk partitions in Linux environment. Now it is not only on Linux systems that LVM disk management mechanism can be used, for other UNIX-like operating systems, as well as windows operating systems, there are similar disk management software like LVM.
The working principle of LVM is actually very simple, it is through the underlying physical hard disk abstractly encapsulated, and then presented to the upper application as a logical volume. In the traditional disk management mechanism, our upper application accesses the file system directly to read the underlying physical hard disk, while in LVM, it encapsulates the underlying physical hard disk. When we operate on the underlying physical hard disk, it is no longer aimed at the partition, but through something called a logical volume to manage the underlying disk. For example, when I add a physical hard disk, the upper service is not felt, because what was presented to the last service was in the form of a logical volume.
The most important feature of LVM is that it can manage the disk dynamically. Because the size of the logical volume can be dynamically resized without losing existing data. If we add a new hard disk, it will not change the existing upper logical volume. As a dynamic disk management mechanism, logical volume technology greatly improves the flexibility of disk management!
Third, the principle of LVM
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, we below through the diagram to explain the principle of logical volumes!
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 now be 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!
On the basic concepts of Linux logical volumes in LVM disk management and what is the working principle of LVM is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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: 235
*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.