In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what is the concept of lvm in linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the concept of lvm in linux"?
In linux, the full name of LVM is "Logical Volume Manager", which means "logical volume management" in Chinese, which is a mechanism for managing disk partitions in Linux environment. LVM is a logical layer built on hard disks and partitions, which can be used to improve the flexibility of disk partition management.
The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
What is LVM?
LVM (Logical Volume Manager), that is, logical volume management, 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 (volume group) to form a storage pool. Administrators are free to create logical volume groups (logical volumes) 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. 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 simply extend the file system across the disk.
Generally speaking, physical disks or partitions are separated, data cannot span disks or partitions, and the size of each disk or partition is fixed, so it is more troublesome to resize. LVM can integrate these underlying physical disks or partitions into a capacity resource pool, which can be divided into logical volumes for upper layer use. its main function is to flexibly adjust the size of logical volumes without shutting down or reformatting (to be exact, the original part does not need to be formatted, only the newly added parts are formatted).
The implementation process of LVM is shown below:
Interpretation of LVM nouns
PV (physical volume): physical volumes are at the bottom of the logical volume management system and can be partitioned to the entire physical hard disk or the actual physical hard disk. It simply delineates a special area in the physical partition to record the management parameters related to LVM.
VG (volume group): a volume group is established on a physical volume. A volume group must include at least one physical volume. After the volume group is established, it can be dynamically added to the volume group. There can be multiple volume groups in a logical volume management system project.
LV (logical volume): logical volumes are based on volume groups. Unallocated space in volume groups can be used to create new logical volumes. After logical volumes are established, the space can be dynamically expanded and reduced.
PE (physical extent): the physical area is the smallest storage unit available for allocation in the physical volume. The physical area size is specified when the volume group is established. Once it is determined that the physical area size of all physical volumes in the same volume group cannot be changed, the physical area size of all physical volumes in the same volume group needs to be the same. After the new pv is added to the vg, the size of the pe automatically changes to the pe size defined in the vg.
LE (logical extent): a logical region is the smallest storage unit in a logical volume that can be allocated, and the size of the logical area depends on the size of the physical area in the volume group in which the logical volume resides. Due to kernel restrictions, a logical volume (Logic Volume) can only contain a maximum of 65536 PE (Physical Extent), so the size of a PE determines the maximum capacity of a logical volume. 4 MB (default) PE determines that the maximum capacity of a single logical volume is 256 GB. If you want to use a logical volume greater than 256g, you need to specify a larger PE when creating a volume group. In Red Hat Enterprise Linux AS 4, the PE size ranges from 8 KB to 16GB and must always be a multiple of 2.
Write mode of LVM
LVM has two write modes: linear mode and stripe mode.
Linear mode is to write one device after another.
The stripe pattern is somewhat similar to RAID0, where data is written separately to each LVM member device.
Because data in stripe mode is not secure, and LVM does not emphasize read and write performance, LVM defaults to linear mode, so that even if one device breaks down, the data on other devices is still there.
How LVM works
LVM maintains a metadata in each physical volume header, and each metadata contains information about the entire VG (volume group: volume group), including the layout configuration of each VG, the number of PV (physical volume: physical volume), the number of LV (logical volume: logical volume), and the mapping of each PE (physical extends: physical expansion unit) to LE (logical extends: physical expansion unit). The information of each PV header in the same VG is the same, which facilitates data recovery in the event of a failure.
LVM provides a LV layer to the upper file system, hiding the operation details. For the file system, the operation on LV is no different from the previous operation on partition. When writing to the LV, the LVM locates the corresponding LE and writes the data to the corresponding PE through the mapping table of the PV header. 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. The key is to establish a mapping relationship between PE and LE. Different mapping rules determine different LVM storage models. LVM supports stripe and mirror for multiple PV.
Advantages and disadvantages of LVM
Advantages:
File systems can span multiple disks, so the file system size is not limited by physical disks.
You can dynamically expand the size of the file system while the system is running.
You can add new disks to LVM's storage pool.
Important data can be mirrored to multiple physical disks.
You can easily export the entire volume group to another machine.
Disadvantages:
You must use the reducevg command when removing a disk from a volume group (this command requires root permission and is not allowed in a snapshot volume group).
When one disk in the volume group is damaged, the entire volume group is affected.
Storage performance is affected by the addition of additional operations.
The method of creating PV/VG/LV
1. Set the system type of each physical disk or partition to Linux LVM, and its system ID is 8e, which is set by t command in the fdisk tool.
[root@localhost ~] # fdisk / dev/sdb... Command (m for help): nPartition type: P primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): pPartition number (2-4, default 2): 2First sector (20973568-62914559, default 20973568): Using default value 20973568Last sector, + sectors or + size {Kjorma M Magi G} (20973568-62914559, default 62914559): + 5G...Command (m for help): tPartition number (1turin2) Default 2): 2Hex code (type L to list all codes): 8e # specifies system id as 8eChanged type of partition 'Linux' to' Linux LVM'...Command (m for help): p.../dev/sdb1 2048 20973567 10485760 8e Linux LVM/dev/sdb2 20973568 31459327 5242880 8e Linux LVMCommand (m for help): W.
2. Initialize each physical disk or partition to PV (physical volume, physical volume)
The commands available at this stage are pvcreate, pvremove, pvscan, pvdisplay (pvs)
1) pvcreate: create a physical volume
Usage: pvcreate [option] DEVICE
Options:
-f: force the creation of logical volumes without user confirmation
-u: specify the UUID of the device
-y: answer all questions, yes
Example pvcreate / dev/sdb1 / dev/sdb2
2) pvscan: scan all physical volumes on the current system
Usage: pvscan [option]
Options:
-e: displays only physical volumes that belong to the output volume group
-n: only physical volumes that do not belong to any volume group are displayed
-u: display UUID
3) pvdisplay: displays the properties of the physical volume
Usage: pvdisplay [PV_DEVICE]
4) pvremove: delete the physical volume information so that it is no longer treated as a physical volume
Usage: pvremove [option] PV_DEVICE
Options:
-f: force deletion
-y: answer all questions, yes
Example pvremove / dev/sdb1
5) pv create and delete examples
[root@localhost ~] # pvcreate / dev/sdb {1 dev/sdb1 2} # initializes two partitions to the physical volume Physical volume "/ dev/sdb1" partition. Physical volume "/ dev/sdb2" successfully created. [root@localhost ~] # pvscan PV / dev/sdb2 lvm2 [5.00 GiB] PV / dev/sdb1 lvm2 [10.00 GiB] Total: 2 [15.00 GiB] / in use: 0 [0] / in no VG: 2 [15.00 GiB] [root@localhost ~] # pvdisplay / dev/sdb1 # shows the physical volume sdb1 Details "/ dev/sdb1" is a new physical volume of "10.00 GiB"-NEW Physical volume-PV Name / dev/sdb1 VG Name PV Size 10.00 GiB Allocatable NO PE Size 0 # because PE is divided in the VG phase So what you see here is 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID GrP9Gi-ubau-UAcb-za3B-vSc3-er2Q-MVt9OO [root@localhost ~] # pvremove / dev/sdb2 # Delete the physical volume information of sdb2 Labels on physical volume "/ dev/sdb2" successfully wiped. [root@localhost ~] # pvscan # you can see that sdb2 is no longer in the PV list PV / dev/sdb1 lvm2 [10.00 GiB] Total: 1 [10.00 GiB] / in use: 0 [0] / in no VG: 1 [10.00 GiB] [root@localhost ~] # pvcreate / dev/sdb2 Physical volume "/ dev/sdb2" successfully created.
3. Create a VG (volume group, volume group).
Volume groups integrate multiple physical volumes (masking the underlying details) and partition PE (physical extend)
PE is the smallest storage unit in a physical volume, somewhat similar to the block,PE size in the file system that can be specified, with a default of 4m. The commands used at this stage are vgcreate, vgscan, vgdisplay, vgextend, vgreduce
1) vgcreate: create a volume group
Usage: vgcreate [option] VG_NAME PV_DEVICE
Options:
-s: the PE size of the physical volume in the volume group. Default is 4m.
-l: the maximum number of logical volumes allowed to be created on the volume group
-p: maximum number of physical volumes allowed to be added at the volume level
Example vgcreate-s 8m myvg / dev/sdb1 / dev/sdb2
2) vgscan: find the LVM volume groups that exist in the system, and display a list of found volume groups
3) vgdisplay: displays volume group properties
Usage: vgdisplay [option] [VG_NAME]
Options:
-A: displays only the information of the active volume group
-s: use short format to output information
4) vgextend: dynamically extends the LVM volume group to increase the capacity of the volume group by adding physical volumes to the volume group
Usage: vgextend VG_NAME PV_DEVICE
Example vgextend myvg / dev/sdb3
5) vgreduce: reduce the volume group capacity by deleting the physical volumes in the LVM volume group, and cannot delete the last remaining physical volume in the LVM volume group
Usage: vgreduce VG_NAME PV_DEVICE
6) vgremove: delete a volume group on which logical volumes must be offline
Usage: vgremove [- f] VG_NAME
-f: force deletion
7) vgchange: commonly used to set the activity status of a volume group
Usage: vgchange-an / y VG_NAME
-a n is dormant. Make sure that all the logical volumes on it are offline before sleeping.
-a y is active
8) vg creation example
[root@localhost] # vgcreate-s 8m myvg / dev/sdb {1MJ 2} Volume group "myvg" successfully created [root@localhost] # vgscan Reading volume groups from cache. Found volume group "myvg" using metadata type lvm2 [root@localhost ~] # vgdisplay-Volume group-VG Name myvg System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size 14.98 GiB PE Size 8.00 MiB Total PE 1918 Alloc PE / Size 0 / 0 Free PE / Size 1918 / 14.98 GiB VG UUID aM3RND-aUbQ-7RjC-dCci-JiS4-Oj2Z-wv9poA
4. Create a LV (logical volume, logical volume) on the volume group
For ease of management, the device file corresponding to the logical volume is saved in the volume group directory as / dev/VG_NAME/LV_NAME. The smallest storage unit that can be allocated in LV is called LE (logical extend). In the same volume group, the size of LE and PE are the same and correspond one to one. Commands used at this stage are lvcreate, lvscan, lvdisplay, lvextend, lvreduce, lvresize
1) lvcreate: create a logical volume or snapshot
Usage: lvcreate [options] [parameters]
Options:
-L: specify the siz
-l: specify the size (number of LE)
-n: specify a name
-s: create a snapshot
-p r: set to read-only (this option is generally used in creating snapshots)
Note: of course, the volume group must be specified when using this command to create logical volumes, and which logical volume must be specified when creating snapshots.
Example lvcreate-L 500m-n mylv myvg
2) lvscan: scan all logical volumes in the current system and their corresponding device files
3) lvdisplay: displays logical volume properties
Usage: lvdisplay [/ dev/VG_NAME/LV_NAME]
4) lvextend: logical volume space can be expanded online
Usage: the size of the lvextend-Lhammerl extension / dev/VG_NAME/LV_NAME
Options:
-L: specifies the size of the extension (after). For example,-L + 800m means to expand 800m, while-L 800m means to expand to 800m
-l: specify the size of the extension (after) (number of LE)
Example lvextend-L 200m / dev/myvg/mylv
5) lvreduce: reduces the space of logical volumes and is generally used offline
Usage: reduced size / dev/VG_NAME/LV_NAME of lvexreduce-L Maximel
Options:
-L: specify the size of the reduction (after)
-l: specify the size of the reduction (after) (number of LE)
Example lvreduce-L 200m / dev/myvg/mylv
6) lvremove: delete a logical volume, which needs to be offline (unmounted)
Usage: lvremove [- f] / dev/VG_NAME/LV_NAME
-f: force deletion
7) lv creation example
[root@localhost ~] # lvcreate-L 2G-n mylv myvg Logical volume "mylv" created. [root@localhost ~] # lvscan ACTIVE'/ dev/myvg/mylv' [2.00 GiB] inherit [root@localhost ~] # lvdisplay-Logical volume-LV Path / dev/myvg/mylv LV Name mylv VG Name myvg LV UUID 2lfCLR- UEhm-HMiT-ZJil-3EJm-n2H3-ONLaz1 LV Write Access read/write LV Creation host Time localhost.localdomain, 2019-07-05 13:42:44 + 0800 LV Status available # open 0 LV Size 2.00 GiB Current LE 256 Segments 1 Allocation inherit Read ahead sectors auto-currently set to 256 Block device 253 open 0
5. Format logical volumes and mount them
[root@localhost ~] # mke2fs-t ext4 / dev/myvg/mylv...Writing inode tables: doneCreating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done... [root@localhost ~] # mkdir / data [root@localhost ~] # mountmount mountpoint [root@localhost ~] # mount / dev/myvg/mylv / data [root@localhost ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/sda1 50G 1.5G 49G 3% / devtmpfs 903M 0903M 0% / devtmpfs 912M 0912M 0 % / dev/shmtmpfs 912M 8.6M 904m 1% / runtmpfs 912M 0912M 0% / sys/fs/cgrouptmpfs 183M 0 183M 0% / run/user/0/dev/mapper/myvg-mylv 2.0G 6.0M 1.8G 1% / data to this I believe you have a deeper understanding of "what is the concept of lvm in linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.