LVM(逻辑卷管理器)可以允许用户对硬盘资源进行动态调整。(让用户灵活的变更分区的大小)
逻辑卷管理器是Linux系统用于对硬盘分区进行管理的一种机制,理论性较强,其创建初衷是为了解决硬盘设备在创建分区后不易修改分区大小的缺陷。尽管对传统的硬盘分区进行强制扩容或缩容从理论上来讲是可行的,但是却可能造成数据的丢失。而LVM技术是在硬盘分区和文件系统之间添加了一个逻辑层,它提供了一个抽象的卷组,可以把多块硬盘进行卷组合并。这样一来,用户不必关心物理硬盘设备的底层架构和布局,就可以实现对硬盘分区的动态调整。LVM的技术架构如图。
LVM的核心理念
1.物理卷处于LVM中的最底层,可以将其理解为物理硬盘、硬盘分区或者RAID磁盘阵列,这都可以。
2.卷组建立在物理卷之上,一个卷组可以包含多个物理卷,而且在卷组创建之后也可以继续向其中添加新的物理卷。
3.逻辑卷是用卷组中空闲的资源建立的,并且逻辑卷在建立后可以动态地扩展或缩小空间。
部署逻辑卷
部署LVM时,需要逐个配置物理卷、卷组和逻辑卷。常用的部署命令如表所示。
部署逻辑卷步骤:(PV -> VG -> LV)
1.让硬盘设备支持LVM技术(pvcreate)。
2.把硬盘设备加入到卷组(vgcreate)。
3.从卷组中切割一定空间作为逻辑卷(lvcreate)。
4.把生成好的逻辑卷进行格式化,然后挂载使用(mkfs,mount,/etc/fstab)。
[root@root ~]# pvcreate /dev/sd[b-c]
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n] y
Wiping dos signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
[root@root ~]# vgcreate vg /dev/sd[b-c]
Volume group "vg" successfully created
[root@root ~]# vgdisplay
--- Volume group ---
VG Name vg
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 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 0 / 0
Free PE / Size 10238 / 39.99 GiB
VG UUID DbDSLo-yPdx-VXxr-O2q6-DPxO-xhLq-7XxgKM
--- Volume group ---
VG Name rhel
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 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 0 / 0
VG UUID SFO8Nb-evGR-E6cu-ys3K-2XVe-0sUu-ff8twr
[root@root ~]# lvcreate -n lv -l 40 vg
WARNING: xfs signature detected on /dev/vg/lv at offset 0. Wipe it? [y/n] y
Wiping xfs signature on /dev/vg/lv.
Logical volume "lv" created
[root@root ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg/lv
LV Name lv
VG Name vg
LV UUID 9lgrzo-NrLZ-3wV2-L8ld-mdEr-fTAT-hzo0Ap
LV Write Access read/write
LV Creation host, time root, 2019-10-15 05:30:37 -0400
LV Status available
# open 0
LV Size 160.00 MiB
Current LE 40
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID NDJOHK-Awvj-4wjs-dU03-kOBe-PJ34-04GkZv
LV Write Access read/write
LV Creation host, time localhost, 2019-09-03 05:21:04 -0400
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID cQ4mpE-Bskn-tY8m-aLzf-7WMk-ikoZ-A99GzC
LV Write Access read/write
LV Creation host, time localhost, 2019-09-03 05:21:04 -0400
LV Status available
# open 1
LV Size 17.51 GiB
Current LE 4482
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@root ~]# mkfs.ext4 /dev/vg/lv
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
40960 inodes, 163840 blocks
8192 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33816576
20 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@root ~]# vim /etc/fstab
[root@root ~]# mount -a
[root@root ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 18G 3.2G 15G 19% /
devtmpfs 986M 0 986M 0% /dev
tmpfs 994M 168K 994M 1% /dev/shm
tmpfs 994M 8.8M 986M 1% /run
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 497M 118M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/mapper/vg-lv 151M 1.6M 139M 2% /lvm
[root@root ~]#