很多国内大神写的流程是
- 使用fdisk创建分区
- 格式化分区
- 使用pvcreate把分区添加到PV中
- 使用vgextend把PV添加到VG中
- 如果使用lvextend之后,使用df -h仍然发现空间没变,就使用 这个方法来处理
我测试的结果是操作步骤太多,而且用df -h查询仍然没增加容量。我找了一些国外的网站,介绍的方法简单一些
- 使用fdisk查询添加的硬盘
[root@ ~]# fdisk -l
Disk /dev/sda: 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 label type: dos
Disk identifier: 0x000da61c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
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
- 直接使用pvcreate把硬盘添加到PV中
pvcreate /dev/sdb
- 使用vgextend把PV添加到PG中
vgextend centos /dev/sdb
- 查看VG信息,并将数据添加到LV中
[root@ ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size <20 GiB
PE Size 4.00 MiB
Total PE 9982
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 5119 / <20.00 GiB
VG UUID VU7hLn-MlMS-PDAz-ZYFv-yEUB-jTmW-tZjrqX
- 这时使用df -h查询空间时,仍然是不变的,需要使用lvextend进行扩容,并且很重要的一点,要使用xfs_growfs命令来刷新容量,这里因为咱们的VG已经是在LV里面的,不需要另外把VG添加到LV中
lvextend -l +5119 /dev/centos/root
xfs_growfs /dev/centos/root
- 要注意的是5119的值是VG的Free PE数量
- 现在再使用df -h命令来查询容量时,容量已经增加了