Linux's lvm partition refers to "logical volume management". The full English name of lvm is "Logical Volume Manager", which is a mechanism for managing disk partitions in the Linux environment; LVM is built on the hard disk and A logical layer above partitions to improve the flexibility of disk partition management.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
1. What is LVM
LVM (Logical Volume Manager), that is, logical volume management, is a mechanism for managing disk partitions in the Linux environment. LVM is built on the hard disk and partition A logical layer on top to improve the flexibility of disk partition management. LVM system administrators can easily manage disk partitions, such as connecting several disk partitions into a volume group to form a storage pool. Administrators can freely create logical volumes on volume groups and further create file systems on logical volume groups. Administrators can easily adjust the size of storage volume groups through LVM, and can name, manage and allocate disk storage according to groups. When a new disk is added to the system, the LVM administrator does not have to move the disk's files to the new disk to make full use of the new storage space, but can directly 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 re-adjustment is troublesome. LVM can integrate these underlying physical disks or partitions, abstract them into capacity resource pools, and divide them into logical volumes for use by the upper layer. Its main function is that it can be used without shutting down or reformatting (to be precise, The size of the logical volume can be flexibly adjusted (the original part does not need to be formatted, only the new part is formatted).
The implementation process of LVM is as follows:

2. LVM terminology explanation
PV( physical volume): The physical volume is at the bottom of the logical volume management system and can be the entire physical hard disk or a partition on the actual physical hard disk. It just sets aside a special area in the physical partition to record management parameters related to LVM.
VG (volume group): Volume groups are created on physical volumes. A volume group must include at least one physical volume. After the volume group is created, volumes 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 built on volume groups. Unallocated space in volume groups can be used to create new logical volumes. Logical volumes can be dynamically expanded and shrunk after they are created. space.
PE(physical extent): The physical area is the smallest storage unit that can be allocated in the physical volume. The physical area size is specified when establishing the volume group. Once determined, it cannot be changed. The physical area size of all physical volumes must be consistent. After a new pv is added to the vg, the pe size is automatically changed to the pe size defined in the vg.
LE(logical extent): The logical area is the smallest storage unit available for allocation in the logical volume. The size of the logical area depends on the size of the physical area in the volume group where the logical volume is located. Due to kernel limitations, a logical volume (Logic Volume) can only contain up to 65536 PE (Physical Extent) , so the size of a PE determines the maximum capacity of the logical volume, 4 MB (default ) determines the maximum capacity of a single logical volume to 256 GB. If you want to use a logical volume larger 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.
3. LVM writing mode
LVM has two writing modes: linear mode and stripe mode.
- Linear mode means writing to one device before writing to another device
- Stripe mode is somewhat similar to RAID0, that is, data is written to each LVM member device in a distributed manner.
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 is broken, the data on other devices is still there.
4. How LVM works
LVM maintains a metadata at the head of each physical volume, and each metadata contains the entire VG (volume group: volume group ) information, including the layout configuration of each VG, the number of PV (physical volume: physical volume), the number of LV (logical volume: logical volume), and each PE (physical extends: physical expansion unit) to LE (logical extends: mapping relationship of physical extension unit). The information in the header of each PV in the same VG is the same, which facilitates data recovery in case of failure.
LVM provides the LV layer for the upper file system, hiding the operation details. For the file system, the operation of LV is no different from the original operation of partition. When writing to the LV, LVM locates the corresponding LE and writes the data to the corresponding PE through the mapping table in the PV header. The biggest feature of LVM is that it can dynamically manage disks. Because the size of the logical volume can be dynamically adjusted 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 of multiple PVs.
5. Advantages and Disadvantages of LVM
Advantages:
- The file system can span multiple disks, so the file system size is not limited by the physical disk.
- The size of the file system can be dynamically expanded while the system is running.
- You can add new disks to the LVM storage pool.
- You can redundant important data to multiple physical disks in a mirroring manner.
- You can easily export the entire volume group to another machine.
Disadvantages:
- The reducevg command must be used when removing a disk from a volume group (this command requires root privileges and is not allowed in snapshot volume groups use).
- When one disk in a volume group is damaged, the entire volume group will be affected.
- Due to the addition of additional operations, storage performance is affected.
6. 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. Use the t command in the fdisk tool to set
[root@localhost?~]#?fdisk?/dev/sdb?...
Command?(m?for?help):?n
Partition?type:
???p???primary?(1?primary,?0?extended,?3?free)
???e???extended
Select?(default?p):?p
Partition?number?(2-4,?default?2):?2First?sector?(20973568-62914559,?default?20973568):?
Using?default?value?20973568Last?sector,?+sectors?or?+size{K,M,G}?(20973568-62914559,?default?62914559):?+5G
...
Command?(m?for?help):?t
Partition?number?(1,2,?default?2):?2Hex?code?(type?L?to?list?all?codes):?8e??#?指定system?id為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?LVM
Command?(m?for?help):?w
...
2. Initialize each physical disk or partition into a PV (physical volume)
The commands that can be used at this stage are pvcreate, pvremove, pvscan, pvdisplay (pvs)
1) pvcreate: Create a physical volume
用法:pvcreate?[option]?DEVICE
??選項(xiàng):
??????-f:強(qiáng)制創(chuàng)建邏輯卷,不需用戶確認(rèn)
??????-u:指定設(shè)備的UUID
??????-y:所有問(wèn)題都回答yes
??例?pvcreate?/dev/sdb1?/dev/sdb2
2) pvscan: Scan all physical volumes on the current system
用法:pvscan?[option]
??選項(xiàng):
??????-e:僅顯示屬于輸出卷組的物理卷
??????-n:僅顯示不屬于任何卷組的物理卷
??????-u:顯示UUID
3) pvdisplay: Display the properties of the physical volume
?用法:pvdisplay?[PV_DEVICE]
4) pvremove: Delete the physical volume information so that it is no longer considered a physical volume
?用法:pvremove?[option]?PV_DEVICE
??選項(xiàng):
??????-f:強(qiáng)制刪除
??????-y:所有問(wèn)題都回答yes
??例?pvremove?/dev/sdb1
5) PV creation and deletion examples
[root@localhost?~]#?pvcreate?/dev/sdb{1,2}??#?將兩個(gè)分區(qū)初始化為物理卷
??Physical?volume?"/dev/sdb1"?successfully?created.
??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???#?顯示物理卷sdb1的詳細(xì)信息
??"/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???#?由于PE是在VG階段才劃分的,所以此處看到的都是0
??Total?PE??????????????0
??Free?PE???????????????0
??Allocated?PE??????????0
??PV?UUID???????????????GrP9Gi-ubau-UAcb-za3B-vSc3-er2Q-MVt9OO
???
[root@localhost?~]#?pvremove?/dev/sdb2???#?刪除sdb2的物理卷信息
??Labels?on?physical?volume?"/dev/sdb2"?successfully?wiped.
[root@localhost?~]#?pvscan?????#?可以看到PV列表中已無(wú)sdb2
??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 VG (volume group). Volume groups integrate multiple physical volumes (shielding the underlying details) and divide PE (physical extend)
PE is the smallest storage unit in a physical volume, somewhat similar to a block in a file system , PE size can be specified, the default is 4M. The commands used at this stage include vgcreate, vgscan, vgdisplay, vgextend, vgreduce
1) vgcreate: Create a volume group
?用法:vgcreate?[option]?VG_NAME?PV_DEVICE
??選項(xiàng):
??????-s:卷組中的物理卷的PE大小,默認(rèn)為4M
??????-l:卷組上允許創(chuàng)建的最大邏輯卷數(shù)
??????-p:卷級(jí)中允許添加的最大物理卷數(shù)
??例?vgcreate?-s?8M?myvg?/dev/sdb1?/dev/sdb2
2) vgscan: Find LVM volume groups that exist in the system and display the list of found volume groups
3) vgdisplay: Display volume group attributes
??用法:vgdisplay?[option]?[VG_NAME]
??選項(xiàng):
??????-A:僅顯示活動(dòng)卷組的信息
??????-s:使用短格式輸出信息
4) vgextend: Dynamically extend LVM volume group, which increases the capacity of the volume group by adding physical volumes to the volume group
?用法:vgextend?VG_NAME?PV_DEVICE
??例?vgextend?myvg?/dev/sdb3
5) vgreduce: Reduce volume group capacity by deleting physical volumes in the LVM volume group. The last remaining physical volume in the LVM volume group cannot be deleted
?用法:vgreduce?VG_NAME?PV_DEVICE
6) vgremove: delete the volume group, the logical volume on it must be offline
??用法:vgremove?[-f]?VG_NAME
??-f:強(qiáng)制刪除
7)vgchange:常用來(lái)設(shè)置卷組的活動(dòng)狀態(tài)
??用法:vgchange?-a?n/y?VG_NAME
??-a?n為休眠狀態(tài),休眠之前要先確保其上的邏輯卷都離線;
??-a?y為活動(dòng)狀態(tài)
8)vg創(chuàng)建例子
[root@localhost?~]#?vgcreate?-s?8M?myvg?/dev/sdb{1,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、在卷組上創(chuàng)建LV(logical volume,邏輯卷)
為了便于管理,邏輯卷對(duì)應(yīng)的設(shè)備文件保存在卷組目錄下,為/dev/VG_NAME/LV_NAME。LV中可以分配的最小存儲(chǔ)單元稱為L(zhǎng)E(logical extend),在同一個(gè)卷組中,LE的大小和PE是一樣的,且一一對(duì)應(yīng)。這一階段用到的命令有l(wèi)vcreate、lvscan、lvdisplay、lvextend、lvreduce、lvresize
1)lvcreate:創(chuàng)建邏輯卷或快照
??用法:lvcreate?[選項(xiàng)]?[參數(shù)]
??選項(xiàng):
??????-L:指定大小
??????-l:指定大小(LE數(shù))
??????-n:指定名稱
??????-s:創(chuàng)建快照
??????-p?r:設(shè)置為只讀(該選項(xiàng)一般用于創(chuàng)建快照中)
??注:使用該命令創(chuàng)建邏輯卷時(shí)當(dāng)然必須指明卷組,創(chuàng)建快照時(shí)必須指明針對(duì)哪個(gè)邏輯卷?????????
??例?lvcreate?-L?500M?-n?mylv?myvg
2)lvscan:掃描當(dāng)前系統(tǒng)中的所有邏輯卷,及其對(duì)應(yīng)的設(shè)備文件
3)lvdisplay:顯示邏輯卷屬性
??用法:lvdisplay?[/dev/VG_NAME/LV_NAME]
4)lvextend:可在線擴(kuò)展邏輯卷空間
??用法:lvextend?-L/-l?擴(kuò)展的大小?/dev/VG_NAME/LV_NAME??
??選項(xiàng):
??????-L:指定擴(kuò)展(后)的大小。例如,-L?+800M表示擴(kuò)大800M,而-L?800M表示擴(kuò)大至800M
??????-l:指定擴(kuò)展(后)的大?。↙E數(shù))
??例?lvextend?-L?200M?/dev/myvg/mylv
5)lvreduce:縮減邏輯卷空間,一般離線使用
?用法:lvexreduce?-L/-l?縮減的大小?/dev/VG_NAME/LV_NAME??
??選項(xiàng):
??????-L:指定縮減(后)的大小
??????-l:指定縮減(后)的大小(LE數(shù))
??例?lvreduce?-L?200M?/dev/myvg/mylv
6)lvremove:刪除邏輯卷,需要處于離線(卸載)狀態(tài)
??用法:lvremove?[-f]?/dev/VG_NAME/LV_NAME
??-f:強(qiáng)制刪除
7)lv創(chuàng)建例子
[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:0
5、格式化邏輯卷并掛載
[root@localhost ~]# mke2fs -t ext4 /dev/myvg/mylv
... ? ? ? ? ? ? ? ? ? ? ? ?
Writing inode tables: done ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
...
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount
mount ? ? ? mountpoint ?
[root@localhost ~]# mount /dev/myvg/mylv /data
[root@localhost ~]# df -h
Filesystem ? ? ? ? ? ? Size ?Used Avail Use% Mounted on
/dev/sda1 ? ? ? ? ? ? ? 50G ?1.5G ? 49G ? 3% /
devtmpfs ? ? ? ? ? ? ? 903M ? ? 0 ?903M ? 0% /dev
tmpfs ? ? ? ? ? ? ? ? ?912M ? ? 0 ?912M ? 0% /dev/shm
tmpfs ? ? ? ? ? ? ? ? ?912M ?8.6M ?904M ? 1% /run
tmpfs ? ? ? ? ? ? ? ? ?912M ? ? 0 ?912M ? 0% /sys/fs/cgroup
tmpfs ? ? ? ? ? ? ? ? ?183M ? ? 0 ?183M ? 0% /run/user/0
/dev/mapper/myvg-mylv ?2.0G ?6.0M ?1.8G ? 1% /data
PS:更新
一、LV邏輯卷擴(kuò)容后,必須對(duì)掛載目錄在線擴(kuò)容。
使用 resize2fs或xfs_growfs 對(duì)掛載目錄在線擴(kuò)容
resize2fs 針對(duì)文件系統(tǒng)ext2 ext3 ext4
xfs_growfs 針對(duì)文件系統(tǒng)xfs
xfs在線擴(kuò)容
xfs_growfs?/dev/mapper/vg--BHG-lv01
meta-data=/dev/mapper/vg--BHG-lv01?isize=512????agcount=4,?agsize=32000?blks
?????????=???????????????????????sectsz=512???attr=2,?projid32bit=1
?????????=???????????????????????crc=1????????finobt=0?spinodes=0data?????=???????????????????????bsize=4096???blocks=128000,?imaxpct=25
?????????=???????????????????????sunit=0??????swidth=0?blksnaming???=version?2??????????????bsize=4096???ascii-ci=0?ftype=1log??????=internal???????????????bsize=4096???blocks=855,?version=2
?????????=???????????????????????sectsz=512???sunit=0?blks,?lazy-count=1realtime?=none???????????????????extsz=4096???blocks=0,?rtextents=0data?blocks?changed?from?128000?to?256000
ext4在線擴(kuò)容
[root@localhost?/]#?resize2fs?/dev/mapper/vg--BHG-lv02
resize2fs?1.42.9?(28-Dec-2013)
Filesystem?at?/dev/mapper/vg--BHG-lv02?is?mounted?on?/BHGPOS-data;?on-line?resizing?required
old_desc_blocks?=?2,?new_desc_blocks?=?3
The?filesystem?on?/dev/mapper/vg--BHG-lv02?is?now?5242880?blocks?long.
相關(guān)推薦:《Linux視頻教程》
The above is the detailed content of What is the lvm partition of linux?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Integrating Postman applications on CentOS can be achieved through a variety of methods. The following are the detailed steps and suggestions: Install Postman by downloading the installation package to download Postman's Linux version installation package: Visit Postman's official website and select the version suitable for Linux to download. Unzip the installation package: Use the following command to unzip the installation package to the specified directory, for example /opt: sudotar-xzfpostman-linux-x64-xx.xx.xx.tar.gz-C/opt Please note that "postman-linux-x64-xx.xx.xx.tar.gz" is replaced by the file name you actually downloaded. Create symbols

The main difference between Java and other programming languages ??is its cross-platform feature of "writing at once, running everywhere". 1. The syntax of Java is close to C, but it removes pointer operations that are prone to errors, making it suitable for large enterprise applications. 2. Compared with Python, Java has more advantages in performance and large-scale data processing. The cross-platform advantage of Java stems from the Java virtual machine (JVM), which can run the same bytecode on different platforms, simplifying development and deployment, but be careful to avoid using platform-specific APIs to maintain cross-platformity.

Setting the location of the interpreter in PyCharm can be achieved through the following steps: 1. Open PyCharm, click the "File" menu, and select "Settings" or "Preferences". 2. Find and click "Project:[Your Project Name]" and select "PythonInterpreter". 3. Click "AddInterpreter", select "SystemInterpreter", browse to the Python installation directory, select the Python executable file, and click "OK". When setting up the interpreter, you need to pay attention to path correctness, version compatibility and the use of the virtual environment to ensure the smooth operation of the project.

The steps to manually install the plug-in package in VSCode are: 1. Download the .vsix file of the plug-in; 2. Open VSCode and press Ctrl Shift P (Windows/Linux) or Cmd Shift P (Mac) to call up the command panel; 3. Enter and select Extensions:InstallfromVSIX..., then select .vsix file and install. Manually installing plug-ins provides a flexible way to install, especially when the network is restricted or the plug-in market is unavailable, but attention needs to be paid to file security and possible dependencies.

[Common Directory Description] Directory/bin stores binary executable files (ls, cat, mkdir, etc.), and common commands are generally here. /etc stores system management and configuration files/home stores all user files. The root directory of the user's home directory is the basis of the user's home directory. For example, the home directory of the user user is /home/user. You can use ~user to represent /usr to store system applications. The more important directory /usr/local Local system administrator software installation directory (install system-level applications). This is the largest directory, and almost all the applications and files to be used are in this directory. /usr/x11r6?Directory for storing x?window/usr/bin?Many

Understanding Nginx's configuration file path and initial settings is very important because it is the first step in optimizing and managing a web server. 1) The configuration file path is usually /etc/nginx/nginx.conf. The syntax can be found and tested using the nginx-t command. 2) The initial settings include global settings (such as user, worker_processes) and HTTP settings (such as include, log_format). These settings allow customization and extension according to requirements. Incorrect configuration may lead to performance issues and security vulnerabilities.

The installation and configuration of MySQL can be completed through the following steps: 1. Download the installation package suitable for the operating system from the official website. 2. Run the installer, select the "Developer Default" option and set the root user password. 3. After installation, configure environment variables to ensure that the bin directory of MySQL is in PATH. 4. When creating a user, follow the principle of minimum permissions and set a strong password. 5. Adjust the innodb_buffer_pool_size and max_connections parameters when optimizing performance. 6. Back up the database regularly and optimize query statements to improve performance.

Informix and MySQL are both popular relational database management systems. They perform well in Linux environments and are widely used. The following is a comparison and analysis of the two on the Linux platform: Installing and configuring Informix: Deploying Informix on Linux requires downloading the corresponding installation files, and then completing the installation and configuration process according to the official documentation. MySQL: The installation process of MySQL is relatively simple, and can be easily installed through system package management tools (such as apt or yum), and there are a large number of tutorials and community support on the network for reference. Performance Informix: Informix has excellent performance and
