[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 2.3G 15G 14% /
/dev/sr0 4.5G 4.5G 0 100% /iso
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
[root@localhost ~]# fdisk -l /dev/sdb /dev/sdc
磁盘 /dev/sdb:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/sdc:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
3、将sdb和sdc创建物理卷,返回创建物理卷成功;注:硬盘可以一块或多块,也可使用格式为8e的分区创建物理卷
[root@localhost ~]# pvcreate /dev/sdb /dev/sdc
Physical volume "/dev/sdb" successfully created.
Physical volume "/dev/sdc" successfully created.
4、查看一下物理卷的信息;
[root@localhost ~]# pvdisplay
"/dev/sdc" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID FddYEs-ANMR-pgBg-AHMY-I6B9-2LIq-jNjaTh
"/dev/sdb" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 00PzWu-qstD-xHRC-vzjf-X27D-lu4u-2rn1x8
5、查看根分区的卷组名称VG name,可以看到为centos;
[root@localhost ~]# 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 <19.00 GiB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0
VG UUID HfWWKM-EgcF-g40V-39zT-ghys-uihW-dMHbzb
6、将sdb和sdc添加到名称为centos的卷组,可以看到返回添加成功;
[root@localhost ~]# vgextend centos /dev/sdb /dev/sdc
Volume group "centos" successfully extended
7、查看逻辑卷信息;
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID dbTv5f-WGBj-rF2W-ZDAk-4cwS-fZKI-egTr7u
LV Write Access read/write
LV Creation host, time 192.168.133.128, 2021-01-17 22:18:54 +0800
LV Status available
# open 1
LV Size <17.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
8、将卷组全部剩余空间添加至逻辑卷;
[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <26.99 GiB (6909 extents).
Logical volume centos/root successfully resized.
9、执行根分区刷新;
[root@localhost ~]# xfs_growfs /dev/centos/root
10、查看扩容后的根分区空间大小,已经为27G;
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 27G 2.3G 25G 9% /
/dev/sr0 4.5G 4.5G 0 100% /iso
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
四、创建LVM卷挂载目录
1、还是以sdb和sdc为例;
[root@localhost ~]# pvcreate /dev/sdb /dev/sdc
Physical volume "/dev/sdb" successfully created.
Physical volume "/dev/sdc" successfully created.
2、创建卷组,vgcreate 卷组名称 /dev/sdb /dev/sdc;
[root@localhost ~]# vgcreate vgtest /dev/sdb /dev/sdc
Volume group "vgtest" successfully created
3、查看卷组信息;
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vgtest
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 9.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 0 / 0
Free PE / Size 2558 / 9.99 GiB
VG UUID JRwmiW-TcAS-558L-oRB4-k0pV-nDeK-bq8W3R
4、创建逻辑卷,lvcreate -l 100%FREE 卷组名称 -n 逻辑卷名称;
[root@localhost ~]# lvcreate -l 100%FREE vgtest -n lvtest
Logical volume "lvtest" created.
5、格式化逻辑卷,可以根据需要选择文件系统格式;
[root@localhost ~]# mkfs -t xfs /dev/vgtest/lvtest
6、挂载逻辑卷;
[root@localhost ~]# mount /dev/vgtest/lvtest /lvtest/
7、df查看已挂载成功;
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 2.3G 15G 14% /
/dev/sr0 4.5G 4.5G 0 100% /iso
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vgtest-lvtest 10G 33M 10G 1% /lvtest