LVM
LVM(Logical Volume Manager)逻辑卷管理,底层是多块磁盘拼凑起来的,跟raid很像。LVM最大特点是便于动态调整磁盘容量
/boot分区用于存放引导文件,不能应用LVM机制
LVM机制的基本概念:
-
物理卷(Physical Volume,PV): 这是实际硬盘驱动器或用fdisk等工具建立的普通分区,包括许多默认4M大小的PE。可以将一个或多个物理卷组合成一个卷组
-
卷组(Volume Group,VG): 由一个或多个物理卷组成,是LVM中的逻辑存储池。卷组是LVM的核心,逻辑卷从卷组分配空间
-
逻辑卷(Logical Volume,LV): 逻辑卷相当于传统硬盘上的分区,但更加灵活。它是从卷组中分配的逻辑块设备,可以被格式化并用作文件系统
-
物理区域(Physical Extent,PE): 物理卷被分成物理区域,通常是4MB或8MB的大小。这些物理区域是LVM中分配和管理存储空间的最小单位
LVM的创建流程
-
创建物理卷(PV): 将硬盘或分区添加到LVM中作为物理卷
[root@localhost tt]# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created. [root@localhost tt]# pvscan PV /dev/sda2 VG centos lvm2 [<19.00 GiB / 0 free] PV /dev/sdc lvm2 [50.00 GiB] Total: 2 [<69.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 1 [50.00 GiB]
-
创建卷组(VG): 将一个或多个物理卷组合成卷组
[root@localhost tt]# vgcreate mail_store /dev/sdc Volume group "mail_store" successfully created [root@localhost tt]# vgscan Reading volume groups from cache. Found volume group "centos" using metadata type lvm2 Found volume group "mail_store" using metadata type lvm2
-
创建逻辑卷(LV): 从卷组中分配逻辑卷
[root@localhost tt]# lvcreate -L 40G -n chen_mail mail_store Logical volume "chen_mail" created. [root@localhost tt]# lvscan ACTIVE '/dev/centos/swap' [2.00 GiB] inherit ACTIVE '/dev/centos/root' [<17.00 GiB] inherit ACTIVE '/dev/mail_store/chen_mail' [40.00 GiB] inherit
-
格式化逻辑卷: 类似于在传统硬盘上创建文件系统
[root@localhost tt]# mkfs.xfs /dev/mail_store/chen_mail meta-data=/dev/mail_store/chen_mail isize=512 agcount=4, agsize=2621440 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=10485760, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=5120, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
-
挂载逻辑卷: 将逻辑卷挂载到文件系统的特定目录
[root@localhost tt]# mount /dev/mail_store/chen_mail /test [root@localhost tt]# vim /etc/fstab [root@localhost tt]# tail -n 1 /etc/fstab /dev/mail_store/chen_mail /test xfs defaults 0 0
命令:
功能 | 物理卷 | 卷组 | 逻辑卷 |
---|---|---|---|
scan扫描 | pvscan | vgscan | lvscan |
create建立 | pvcreate | vgcreate | lvcreate |
display显示 | pvdisplay | vgdisplay | lvdisplay |
remove删除 | pvremove | vgremove | lvremove |
extend扩展 | vgextend | lvextend | |
reduce减少 | vgreduce | lvresize |
扩容
# 扩容
lvextend -L +5G /dev/mail_store/chen_mail
# 让Linux内核重新识别lv的大小
xfs_growfs /dev/mail_store/chen_mail