In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what is the use of lvm in linux. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
I. Preface
Every Linux user will encounter this dilemma when installing Linux: when partitioning the system, how to accurately evaluate and allocate the capacity of each hard disk partition, because the system administrator should not only consider the current capacity of a partition, but also foresee the maximum capacity that may be needed in the future. Because if the estimate is not accurate, the administrator may even have to back up the entire system, clear the hard drive, repartition the hard drive, and then restore the data to the new partition when there is not enough partition.
Although there are many tools available to dynamically adjust disks, such as PartationMagic, etc., it does not completely solve the problem, because a partition may be exhausted again On the other hand, this requires a reboot of the system, downtime is unacceptable for many critical servers, and for adding new hard drives, when you want a file system that spans multiple hard drives, the partition adjustment program won't solve the problem.
Therefore, the perfect solution should be to adjust the size of the file system freely under the premise of zero downtime, which is convenient for the file system to span different disks and partitions. Fortunately, the logical volume management (LVM,LogicalVolumeManager) mechanism provided by Linux is a perfect solution.
LVM is the abbreviation of logical disk Volume Management (LogicalVolumeManager). It is a mechanism for managing disk partitions in Linux environment. LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management. LVM system administrators can easily manage disk partitions, such as connecting several disk partitions into a single block volume group (volumegroup) to form a storage pool. Administrators are free to create logical volume groups (logicalvolumes) on volume groups and further create file systems on logical volume groups. Administrators can easily resize storage volume groups through LVM, and disk storage can be named, managed, and allocated according to groups, such as "development" and "sales", instead of using physical disk names "sda" and "sdb". And when the system adds a new disk, the LVM administrator does not have to move the files from the disk to the new disk to make full use of the new storage space, but directly extends the file system across the disk.
II. Basic terminology of LVM
As mentioned earlier, LVM is a logical layer added between the disk partition and the file system to shield the underlying disk partition layout for the file system, provide an abstract volume, and establish the file system on the volume. First, let's discuss the following LVM terms:
Physical storage media (Thephysicalmedia)
In this case, the storage device of the system: the hard disk, such as / dev/hda, / dev/sda, etc., is the storage unit at the lowest level of the storage system.
Physical Volume (physicalvolume)
A physical volume refers to a hard disk partition or a device that logically has the same function as a disk partition (such as RAID). It is the basic storage logic block of LVM, but compared with the basic physical storage media (such as partitions, disks, etc.), it contains management parameters related to LVM.
Volume Group (VolumeGroup)
LVM volume groups are similar to physical hard disks in non-LVM systems and are made up of physical volumes. You can create one or more "LVM partitions" (logical volumes) on a volume group, and the LVM volume group consists of one or more physical volumes.
Logical Volume (logicalvolume)
LVM's logical volumes are similar to hard disk partitions in non-LVM systems, and file systems can be built on top of logical volumes (such as / home or / usr, etc.).
PE (physicalextent)
Each physical volume is divided into basic units called PE (PhysicalExtents), and PE with a unique number is the smallest unit that can be addressed by LVM. The size of PE is configurable and defaults to 4MB.
LE (logicalextent)
Logical volumes are also divided into basic addressable units called LE (LogicalExtents). In the same volume group, the size of LE and PE are the same and correspond one to one.
First, you can see that the physical volume (PV) is made up of a base unit of the same size, PE.
A volume group consists of one or more physical volumes
As you can see from the figure above, PE and LE have an one-to-one correspondence. Logical volumes are built on volume groups. A logical volume is equivalent to a disk partition of a non-LVM system on which a file system can be created.
The following figure is a schematic diagram of the logical relationship between disk partitions, volume groups, logical volumes, and file systems:
Just as non-LVM systems store metadata containing partition information in the partition table at the beginning of the partition, logical volumes and volume group related metadata are 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 starts LVM, activate VG and load the VGDA into memory to identify the actual physical storage location of the LV. When the system performs an iCandle O operation, it accesses the actual physical location according to the mapping mechanism established by VGDA.
Third, install LVM
First determine if the lvm tool is installed on the system:
[root@wwwroot] # rpm-qa | greplvm
Lvm-1.0.3-4
If the command result input is similar to the above example, then the system has installed the LVM management tool; if the command has no output, it means that the LVM management tool is not installed, then you need to download it from the network or install the LVMrpm toolkit from the CD.
After installing the RPM package for LVM, you also need to configure the kernel to support LVM to use LVM. The default kernel of RedHat supports LVM. If you need to recompile the kernel, you need to enter the Multi-deviceSupport (RAIDandLVM) submenu when configuring the kernel, and select the following two options:
[*] Multipledevicesdriversupport (RAIDandLVM)
Logicalvolumemanager (LVM) Support
Then recompile the kernel to add LVM support to the new kernel.
In order to use LVM, make sure that LVM is activated when the system starts. Fortunately, in later versions of RedHat7.0, the system startup script already has support for activating LVM, with the following in / etc/rc.d/rc.sysinit:
# LVMinitialization
If [- e/proc/lvm-a-x/sbin/vgchange-a-f/etc/lvmtab]; then
Action$ "SettingupLogicalVolumeManagement:" / sbin/vgscan&&/sbin/vgchange-ay
Fi
The key is two commands, the vgscan command scans all disks to get volume group information, and creates file volume group data files / etc/lvmtab and / etc/lvmtab.d/*;vgchange-ay commands to activate all volume groups of the system.
Create and manage LVM
To create a LVM system, you generally need to go through the following steps:
1. Create a partition
Use partition tools (such as fdisk, etc.) to create LVM partitions in the same way as other general partitions, except that the partition type of LVM is 8e.
2. Create a physical volume
The command to create a physical volume is pvcreate, which creates all partitions or disks that you want to add to the volume group as physical volumes. The command to create the entire disk as a physical volume is:
# pvcreate/dev/hdb
The command to create a single partition as a physical volume is:
# pvcreate/dev/hda5
3. Create a volume group
The command to create a volume group is vgcreate, which creates a complete volume group from the physical volume established using pvcreate:
# vgcreateweb_document/dev/hda5/dev/hdb
The first argument to the vgcreate command is to specify the logical name of the volume group: web_document. The latter parameter is to specify all partitions and disks that you want to add to the volume group. In addition to creating a volume group web_document, vgcreate also sets to use a PE of size 4MB (default is 4MB), which means that all logical volumes created on the volume group are expanded or shrunk in increments of 4MB. Due to kernel reasons, the PE size determines the maximum size of the logical volume. The PE of 4MB determines that the maximum capacity of a single logical volume is 256GB. If you want to use a logical volume larger than 256g, specify a larger PE when creating a volume group. The PE size ranges from 8KB to 512MB and must always be a multiple of 2 (specified using-s, see manvgcreate for details).
4. Activate the volume group
To use the volume group immediately instead of restarting the system, you can use vgchange to activate the volume group:
# vgchange-ayweb_document
5. Add a new physical volume to the volume group
When the system installs a new disk and creates a new physical volume, and you want to add it to an existing volume group, you need to use the vgextend command:
# vgextendweb_document/dev/hdc1
Here / dev/hdc1 is the new physical volume.
6. Delete a physical volume from the volume group
To delete a physical volume from a volume group, first to verify that the physical volume to be deleted is not in use by any logical volume, use the pvdisplay command to view the physical volume information:
If a physical volume is being used by a logical volume, you need to back up the data of that physical volume somewhere else and then delete it. The command to delete the physical volume is vgreduce:
# vgreduceweb_document/dev/hda1
7. Create a logical volume
The command to create a logical volume is lvcreate:
# lvcreate-L1500-nwww1web_document
This command creates a logical volume with the name www1 and size 1500m on the volume group web_document, and the device entry is / dev/web_document/www1 (web_document is the volume group name and www1 is the logical volume name). If you want to create a logical volume that uses all volume groups, you need to first look at the PE number of the volume group, and then specify when you create the logical volume:
# vgdisplayweb_document | grep "TotalPE"
TotalPE45230
# lvcreate-l45230web_document-nwww1
8. Create a file system
The author recommends using the reiserfs file system instead of ext2 and ext3:
Once you have created the file system, you can load it and use it:
# mkdir/data/wwwroot
# mount/dev/web_document/www1/data/wwwroot
If you want the file system to be loaded automatically when the system starts, you also need to add something to / etc/fstab:
/ dev/web_document/www1/data/wwwrootreiserfsdefaults12
9. Delete a logical volume
Before deleting a logical volume, you need to unmount it, and then delete it:
# umount/dev/web_document/www1
# lvremove/dev/web_document/www1
Lvremove--doyoureallywanttoremove "/ dev/web_document/www1"? [YPao]: y
Lvremove--doingautomaticbackupofvolumegroup "web_document"
Lvremove--logicalvolume "/ dev/web_document/www1" successfullyremoved
10. Expand the logical volume size
People who are used to traditional hard disk adjustment tools may think that the file system and the partition of the hard disk are unified, but in fact they are not complete (which is why BSD can make multiple file system partitions in a single hard disk partition). Imagine a bookcase with a mobile bookshelf. You can adjust the position of the books in the bookcase through the mobile bookshelf. Think of books as a file system, you can fill the bookcase with books, or you can adjust the space of the bookcase through mobile bookshelves. Of course, you can also adjust the location of books in the bookcase through the bookshelf. As shown in the following figure:
|
+-+ +
| | xxxxxxxxxxx | xxxxxx |
| | xxxxxxxxxxx | xxxxxx |
+-+ +
The file system in the hard disk partition / dev/hda1 occupies the entire partition, while the file system in / dev/hda2 occupies only about 2max 3 partitions.
Therefore, when adjusting the logical volume capacity, we should also adjust the size of the file system on the volume. When you want to increase the capacity, adjust the capacity first, then adjust the file system, and vice versa if you want to reduce the capacity.
LVM provides the ability to easily resize logical volumes, and the command to expand the logical volume size is lvextend:
# lvextend-L12G/dev/web_document/www1
Lvextend--extendinglogicalvolume "/ dev/web_document/www1" to12GB
Lvextend--doingautomaticbackupofvolumegroup "web_document"
Lvextend--logicalvolume "/ dev/web_document/www1" successfullyextended
The above command expands the size of the logical volume www1 to 12G.
# lvextend-L+1G/dev/web_document/www1
Lvextend--extendinglogicalvolume "/ dev/web_document/www1" to13GB
Lvextend--doingautomaticbackupofvolumegroup "web_document"
Lvextend--logicalvolume "/ dev/web_document/www1" successfullyextended
The above command increases the size of the logical volume www1 by 1G.
After you increase the capacity of the logical volume, you need to modify the file system size to take advantage of the expanded space. The author recommends using the reiserfs file system instead of ext2 or ext3. So only the case of reiserfs is discussed here. The Reiserfs file tool provides a file system sizing tool: resize_reiserfs. For file systems that you want to resize to be loaded:
# resize_reiserfs-f/dev/web_document/www1
It is generally recommended that you unmount the file system, resize it, and then load it:
# umount/dev/web_document/www1
# resize_reiserfs/dev/web_document/www1
# mount-treiserfs/dev/web_document/www1/data/wwwroot
For users using ext2 or ext3 file systems, consider using tools
Ext2resize . Http://sourceforge.net/projects/ext2resize
11. Reduce logical volume size
You can use lvreduce to achieve the capacity of logical volumes, and you also need to unmount the file system first:
# umount/data/wwwroot
# resize_reiserfs-s-2G/dev/web_document/www1
# lvreduce-L-2G/dev/web_document/www1
# mount-treiserfs/dev/web_document/www1/data/wwwroot
This is the end of this article on "what is the use of lvm in linux?". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out 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: 227
*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.