1. Introduction
LVM is the abbreviation of Logical Volume Manager (Logical Volume Manager). It is a mechanism for managing disk partitions in the Linux environment. LVM is a logical layer built on hard disks and partitions to improve disk partitioning. Management flexibility.
The biggest feature of LVM is that it can dynamically manage disks. LVM is used to manage the partition, and the size of the partition is dynamically adjusted, which is impossible with standard partitions!
II. Components included in LVM
PV (Physical Volume) Physical Volume
Physical The volume is at the bottom of the logical volume management. It can be a partition on an actual physical hard disk, it can be an entire physical hard disk, or it can be a raid device.
VG (Volume Group) Volume Group
< span style="font-size: 18px;"> Volume groups are built on physical volumes. A volume group must include at least one physical volume. After the volume group is created, physical volumes can be dynamically added to the volume group.
A logical volume management system project can have only one volume group or multiple volume groups.
LV (Logical Volume) logical volume
The logical volume is built on the volume group. The unallocated space in the volume group can be used to create a new logical volume. After the logical volume is created, the space can be dynamically expanded and reduced.
Multiple logical volumes in the system can belong to the same volume group, or they can belong to different volume groups.
PE (Physical Extent) physical block
PE is the smallest storage block of the entire LVM. By default, each PE block is 4MB in size. In other words, our data is actually processed by writing to the PE. Simply put, this PE is a bit like the block size in the file system.
3. Steps to build LVM:
A new physical disk or partition is required
Build the physical partition/or the entire disk into a physical volume (PV)
Consolidate physical volumes into a volume group (VG). The volume group can already be dynamically resized, and the physical volume PV can be added to the volume group to achieve expansion
Divide the volume group into logical volumes (LV). Of course, logical volumes can also be resized directly. For upper-level applications or users, logical volumes are partitions, so they also need to be formatted and mounted.
Create simplified: partition create pv create vg create lv format mount
Delete simplified: uninstall delete lv delete vg delete pv
Create PV #pvcreate
Example: pvcreate /dev/sdb1
Remove PV #pvremove
Example: pvremove /dev/sdb1
pvdisplay #View pv
< span style="font-size: 18px;">Create a VG #vgcreate Example: vgcreate vg1 /dev/sdb1 Delete VG vgremove vg1 /dev/sdb1 Example: vgremove vgdisplay #View vg Common options: -s PE size: Specify the size of the PE, the unit can be MB, GB, TB, etc. If you don’t write the default PE size of 4MB, generally don’t change it vgdisplay #View VG
Create LV #lvcreate
Example: lvcreate -L 5G -n lv1 vg1 #Create a 5G lv1
Remove LV #lvremove
Example: lvremove -L 5G -n lv1 vg1
Common options:
-L capacity: specify the size of the logical volume, the unit is MB, GB, TB, etc.
-l number: specify the size of the logical volume according to the number of PEs
-n logical volume name: specify the logical volume name
lvs format LV mkfs.xfs /dev/vg0/lv1
Mount mkdir /mnt/lv1
mount /dev/vg0/lv1 /mnt/lv1/
four. LVM expansion
The biggest advantage of LVM is that it can dynamically manage disks without losing existing data. If the usage of lv1 reaches 80% and needs to be expanded, then the VG should be expanded first
Increase the PV, and then add the new PV to the VG
Expansion of VG vgextend vg1 /dev/sdc1 Volume group vg1 expansion
Expansion of LV
Check the remaining capacity of vg1 and decide how much to expand to expand lv1.
# lvextend -L +1G /dev/vg1/lv1 Yes +: add 1G to the original basic quality
# lvextend -L 30G /dev/vg1/lv1 No +: capacity changed to 30G
5. LVM reduction
Command: vgreduce lvreduce
Note: In general, we expand the disk capacity, and there is no practical significance in reducing it.
A new physical disk or partition is required
Build the physical partition/or the entire disk into a physical volume (PV)
Consolidate physical volumes into a volume group (VG). The volume group can already be dynamically resized, and the physical volume PV can be added to the volume group to achieve expansion
Divide the volume group into logical volumes (LV). Of course, logical volumes can also be resized directly. For upper-level applications or users, logical volumes are partitions, so they also need to be formatted and mounted.
Create simplified: partition Create pv create vg create lv format mount
Delete simplified: uninstall delete lv delete vg delete pv
Create PV #pvcreate
Example: pvcreate /dev/sdb1
Remove PV #pvremove
Example: pvremove /dev/sdb1
pvdisplay #View pv
Create VG #vgcreate
Example: vgcreate vg1 /dev/sdb1
Delete VG vgremove vg1 /dev/sdb1
Example: vgremove
vgdisplay #View vg
Common options:
-s PE size: Specify the size of the PE, the unit can be MB, GB, TB, etc. If you don’t write the default PE size of 4MB, generally don’t change it
vgdisplay #View VG
Create LV #lvcreate
Example: lvcreate -L 5G -n lv1 vg1 #Create a 5G lv1
Remove LV #lvremove
Example: lvremove -L 5G -n lv1 vg1
Common options:
-L capacity: specify the size of the logical volume, the unit is MB, GB, TB, etc.
-l number: specify the size of the logical volume according to the number of PEs
-n logical volume name: specify the logical volume name
lvs format LV mkfs.xfs /dev/vg0/lv1
Mount mkdir /mnt/lv1
mount /dev/vg0/lv1 /mnt/lv1/