LVM逻辑卷

LVM是 Logical Volume Manager(逻辑卷管理)的简写,LVM通常用于装备大量磁盘的系统,但它同样适于仅有一、两块硬盘的小系统。

磁盘--物理卷---卷组---逻辑卷

  基本概念:
1、 物理卷-----PV(Physical Volume)
物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘。
2、 卷组--------VG(Volumne Group)
卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组。
3、 逻辑卷-----LV(Logical Volume)
逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷要以属于同一个卷组,也可以属于不同的多个卷组。
4、 物理区域--PE(Physical Extent)
物理区域是物理卷中可用于分配的最小存储单元,物理区域的大小可根据实际情况在建立物理卷时指定。物理区域大小一旦确定将不能更改,同一卷组中的所有物理卷的物理区域大小需要一致。
5、 逻辑区域―LE(Logical Extent)
逻辑区域是逻辑卷中可用于分配的最小存储单元,逻辑区域的大小取决于逻辑卷所在卷组中的物理区域的大小。

查看服务器卷组(VG)、物理卷(PV)、逻辑卷(LV)相关信息的命令:

vgscan:查找系统中存在的LVM卷组。显示卷组名和LVM元数据类型。

vgdisplay:查看卷组详细信息。

pvscan:查看系统中所有连接硬盘,显示出物理卷。

lvscan:查看所有LVM的逻辑卷(LV)。

创建逻辑卷 (磁盘的分区,单个磁盘):

0. 准备物理磁盘   /dev/sdb /dev/sdc

[root@test1 ~]# yum install lvm2 -y

[root@test1 ~]# rpm -qa|grep lvm
lvm2-libs-2.02.187-6.el7_9.5.x86_64
lvm2-2.02.187-6.el7_9.5.x86_64

[root@test1 ~]# ll /dev/sd*

brw-rw----. 1 root disk 8,  0 Jun  6 01:44 /dev/sda
brw-rw----. 1 root disk 8,  1 Jun  6 01:44 /dev/sda1
brw-rw----. 1 root disk 8,  2 Jun  6 01:44 /dev/sda2
brw-rw----. 1 root disk 8, 16 Jun  6 01:44 /dev/sdb
brw-rw----. 1 root disk 8, 32 Jun  6 01:44 /dev/sdc
[root@test1 ~]# fdisk -l 

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00094df6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 48.4 GB, 48444211200 bytes, 94617600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@test1 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        46G  2.0G   44G   5% /
/dev/sda1               xfs      1014M  194M  821M  20% /boot
tmpfs                   tmpfs     379M     0  379M   0% /run/user/0
[root@test1 ~]# pvcreate /dev/sdb /dev/sd
sda   sda1  sda2  sdb   sdc   
1. pv(创建物理卷) [root@test1 ~]# pvcreate /dev/sdb /dev/sdc Physical volume "/dev/sdb" successfully created. Physical volume "/dev/sdc" successfully created. [root@test1 ~]# pvscan PV /dev/sda2 VG centos lvm2 [<49.00 GiB / 4.00 MiB free] PV /dev/sdb lvm2 [10.00 GiB] PV /dev/sdc lvm2 [20.00 GiB] Total: 3 [<79.00 GiB] / in use: 1 [<49.00 GiB] / in no VG: 2 [30.00 GiB]

2. vg (创建卷组)

[root@test1 ~]# vgcreate vg1 /dev/sdb /dev/sdc 
Volume group "vg1" successfully created


[root@test1 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <49.00g 4.00m vg1 2 0 0 wz--n- 29.99g 29.99g [root@test1 ~]# vgscan Reading volume groups from cache. Found volume group "centos" using metadata type lvm2 Found volume group "vg1" using metadata type lvm2 [root@test1 ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <49.00 GiB PE Size 4.00 MiB Total PE 12543 Alloc PE / Size 12542 / 48.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID JhOMrz-Ht9H-eyk6-jLjj-5e3q-1r5L-62Ay9w --- Volume group --- VG Name vg1 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 29.99 GiB PE Size 4.00 MiB Total PE 7678 Alloc PE / Size 0 / 0 Free PE / Size 7678 / 29.99 GiB VG UUID 9NrTth-5peS-eBxs-sXTS-1uu7-2EHJ-Y1NMbb [root@test1 ~]# lvs lvs lvscan [root@test1 ~]# lvscan ACTIVE '/dev/centos/root' [<45.12 GiB] inherit ACTIVE '/dev/centos/swap' [<3.88 GiB] inherit
3. lv (创建逻辑卷) [root@test1 ~]# lvcreate -L 29.99G -n lv1 vg1 Rounding up size to full physical extent 29.99 GiB Logical volume "lv1" created.
4. 创建文件系统并挂载
[root@test1 ~]# mkfs.xfs -f /dev/vg1/lv1 meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=1965568 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=7862272, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=3839, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
[root@test1 ~]# vim /etc/fstab
/dev/vg1/lv1 /mnt/lv1 xfs defaults 0 0
[root@test1 ~]# mount -a
[root@test1 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        46G  2.0G   44G   5% /
/dev/sda1               xfs      1014M  194M  821M  20% /boot
tmpfs                   tmpfs     379M     0  379M   0% /run/user/0
/dev/mapper/vg1-lv1     xfs        30G   33M   30G   1% /data
原文地址:https://www.cnblogs.com/xiaoai666/p/14855983.html