1.lvm介绍
1.1LVM基本组成
LVM利用Linux内核的device-mapper来实现存储系统的虚拟化(系统分区独立于底层硬件)。 通过LVM,你可以实现存储空间的抽象化并在上面建立虚拟分区(virtual partitions),可以更简便地扩大和缩小分区,可以增删分区时无需担心某个硬盘上没有足够的连续空间, LVM是用来方便管理的,不会提供额外的安全保证。
1.2LVM的基本组成块(building blocks)
物理卷Physical volume(PV):可以在上面建立卷组的媒介,可以是硬盘分区,也可以是硬盘本身或者回环文件(loopbackfile)。物理卷包括一个特殊的header,其余部分被切割为一块块物理区域(physical extents)。 卷组Volume group (VG):将一组物理卷收集为一个管理单元。 逻辑卷Logical volume (LV):虚拟分区,由物理区域(physical extents)组成。 物理区域Physical extent (PE):硬盘可供指派给逻辑卷的最小单位(通常为4MB)。
2.扩容root分区演示
2.1系统版本
[root@liang ~]
CentOS Linux release 7.2 .1511 (Core )
[root@liang ~]
3.10 .0 -327 .el7.x86_64
2.2查看分区信息及卷组信息
[root@liang ~]
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18 G 989 M 17 G 6 % /
devtmpfs 479 M 0 479 M 0 % /dev
tmpfs 489 M 0 489 M 0 % /dev/shm
tmpfs 489 M 6.7 M 483 M 2 % /run
tmpfs 489 M 0 489 M 0 % /sys/fs/cgroup
/dev/sda1 497 M 140 M 358 M 29 % /boot
tmpfs 98 M 0 98 M 0 % /run /user/0
[root@liang ~]
VG
centos 1 2 0 wz
[root@liang ~]
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao
swap centos -wi-ao
2.4添加一块新磁盘
[root@localhost ~]
Disk /dev/sdb : 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
2.5创建pv
[root@localhost ~]
Physical volume "/dev/sdb" successfully created
[root@localhost ~]
"/dev/sdb" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID CGcA9B-BGk1-rw4h-H7B1-q24G-92 bB-D97QJC
2.6将/dev/sdb pv添加到卷组中
[root@liang ~]
VG
centos 1 2 0 wz--n- 19.51 g 40.00 m
[root@localhost ~]
Volume group "centos" successfully extended
[root@localhost ~]
VG
centos 2 2 0 wz--n- 39.50 g 20.04 g
2.7 扩容根分区
[root@localhost ~]
Size of logical volume centos/root changed from 17.47 GiB (4472 extents) to 22.47 GiB (5752 extents).
Logical volume root successfully resized.
[root@localhost ~]
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 989M 17G 6% /
2.8扩容生效(XFS格式的磁盘不支持减少空间)
[root@localhost ~]
meta-data=/dev/mapper/centos-root isize=256 agcount=4 , agsize=1144832 blks
= sectsz=512 attr=2 , projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=4579328 , imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560 , version =2
= sectsz=512 sunit=0 blks, lazy-count =1
realtime =none extsz=4096 blocks=0 , rtextents=0
data blocks changed from 4579328 to 5890048
[root@localhost ~]
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 23 G 989 M 22 G 5 % /