LVM logical volume (detailed tutorial with pictures and text)

Table of contents

1. Introduction to the concept of disk logical volume management

2. LVM logical volume management commands

3. Common fdisk commands

4. Operation

1. Install the plug-ins required by LVM (usually they come with them)

2. Check the disk

 3. Disk partition (PE)

 4. PV physical volume

 5. VG volume group

 6. LV logical volume

7. File system creation 

 8. Mount

9. Test


1. Introduction to the concept of disk logical volume management

1. LVM is the abbreviation of Logical Volume Manager. It is a mechanism for managing disk partitions in the Linux environment. A common and difficult problem encountered when installing the Linux operating system is how to correctly Evaluate the size of each partition to allocate appropriate hard disk space; the ordinary disk partition management method cannot change the size of the logical partition after it is divided; with the emergence of Linux's logical volume management function, these problems are easily solved, and users do not need to shut down You can easily adjust the size of each partition under certain circumstances, that is, dynamically adjust the disk capacity, thereby improving the flexibility of disk management.

2. Words used in the process of LVM disk elastic management:

1.PE (Physical Extend): physical area

The minimum storage unit that can be allocated in a PV can be specified when creating a PV (default is 4MB), such as 1M, 2M, 4M, 8M, 32M, 64M... The PE size of all PVs that make up the same VG should be the same.

2.PV (Physical Volume): physical volume

At the bottom of LVM, it can be a physical hard disk or partition, an entire hard disk, or a common partition created using tools such as fdisk, including many PEs (Physical Extent, basic unit) with a default size of 4MB.

3.VG (Volume Group): Volume Group

Built on PV, it can contain one to multiple PVs and one or more physical volumes as a whole.

4.LV (Logical Volume): Logical volume

Built on VG, it is equivalent to the concept of the original partition, but the size can be changed dynamically. A space divided from a volume group and used to create a file system.

Process: PV(PE)-->VG-->LV-->Directory mounting

2. LVM logical volume management commands

Function PV physical volume command VG volume group command LV logical volume command
scanning pvscan vgscan lvscan
Establish pvcreate vgcreate lvcreate
Inquire pvdisplay vgdisplay lvdisplay
delete pvremove vgremove lvremove
Expansion vgextend lvextend
shrink vgreduce lvreduce

3. Common fdisk commands

fdisk -l: View the current disk partition status

fdisk /dev/vdb: Partition this disk

m: List all commands

p: Print out the current partition status

n: Create a new partition

d: delete partition

w: save and exit

t: Code to modify the disk

4. Operation

1. Install the plug-ins required by LVM (usually they come with them)

yum -y install lvm2

2. Check the disk

#查看磁盘分区
fdisk -l

 3. Disk partition (PE)

#对新加的磁盘分区
fdisk /dev/新加的磁盘名

w 保存即出

#注:注意将分区id修改为8e

#查看相应的分区文件
ll /dev/新加的磁盘名*

 4. PV physical volume

#1、把分区设为pv物理卷(建立)
#pvcreate /dev/磁盘分区名 /dev/磁盘分区名,如:
pvcreate /dev/vdb1 /dev/vdb2

#简单检查	pvs  #详细查看	pvdisplay

 5. VG volume group

#2、把pv物理卷设为VG卷组(建立)
#vgcreate VG卷组名 /dev/磁盘分区名 /dev/磁盘分区名,如:
vgcreate vg1 /dev/vdb1 /dev/vdb2

#扩容
vgextend vg1 /dev/vdc1

#简单检查	vgs  #详细查看	vgdisplay

 6. LV logical volume

#3、把VG卷组设为LV逻辑卷(建立)
#lvcreate -L 要给的容量 -n LV逻辑卷名 给容量的vg卷组名,如:
lvcreate -L 1T -n lv1 vg1

#扩容
lvextend -l +100%free -r /dev/vg1/lv1 

#简单检查	lvs  #详细查看	lvdisplay

7. File system creation 

#4、文件系统创建,我这用的是ext4 ,也可用XFS
mkfs -t ext4 /dev/vg1/lv1

The default file system starting from centos7.0 is xfs, centos6 is ext4, centos5 is ext3

EXT4

Ext4 is the abbreviation of the fourth generation extended file system, which was launched in 2008. It's a really solid file system, it's been the default option in almost most distributions over the past few years, and it's built from older code. It is a journaling file system, which means that it records the location of files on the disk and any other changes to the disk. If the system crashes, thanks to journal technology, the file system is rarely damaged.

XFS

XFS is a very excellent log file system designed by SGI. XFS comes with various improvements that enable it to stand out in the file system crowd list, such as logging for metadata operations, scalable/parallel I/O, suspend/resume I/O, online defragmentation, delayed performance allocation ,etc

Disadvantages: The XFS file system cannot be shrunk, and performance will decrease when a large number of files are deleted.

The difference between xfs and ext4:

Difference 1: The size of a single file can be 16GB to 16TB in EXT4, while XFS can be 16TB to 16EB.

Difference 2: The maximum file system size of EXT4 can be 1EB, while XFS can be 8EB.

Difference three: EXT4 is limited by disk structure and compatibility issues, and its scalability and scalability are not as good as XFS.

Difference 4: ext4 supports expansion and reduction operations; xfs only supports expansion

 8. Mount

#挂载
#mount /dev/vg1/lv1 要挂载的目录
mount /dev/vg1/lv1 /home/postgres/pgxl10/data/nodes/dn_master


#查看
df -h

9. Test

Upload the file to the mounting directory, and then check whether the mounted disk memory is used

Guess you like

Origin blog.csdn.net/weixin_68547003/article/details/131696934