LVM实现新挂载磁盘扩容到原有目录

 #查看磁盘
fdisk -l
#创建pv
pvcreate /dev/sdb
[root@VM-67-49 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@VM-67-49 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 29.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 7554
Free PE 10
Allocated PE 7544
PV UUID jfRAJl-pnUs-8lXi-1F37-IX3t-Nq8S-RdtQvq "/dev/sdb" is a new physical volume of "100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ggiAwS-NizD-1liX-7b5i-fqpR-ZKL8-t8aZqD
#查看VG
[root@VM-67-49 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
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 129.50 GiB
PE Size 4.00 MiB
Total PE 33153
Alloc PE / Size 33153 / 129.50 GiB
Free PE / Size 0 / 0
VG UUID Y9ksOO-scOb-2VAn-bGUB-vX9U-oVee-mPt59q
[root@VM-66-82 ~]# vgextend centos /dev/sdb
Volume group "centos" successfully extended
[root@VM-66-82 ~]# lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from 26.51 GiB (6786 extents) to 126.50 GiB (32385 extents).
Logical volume centos/root successfully resized.
#创建vg
lvextend -l +100%FREE /dev/mapper/centos-root
#查看文件系统
[root@VM-67-49 ~]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root xfs 27740944 9828872 17912072 36% /
devtmpfs devtmpfs 3994572 0 3994572 0% /dev
tmpfs tmpfs 4005240 0 4005240 0% /dev/shm
tmpfs tmpfs 4005240 403684 3601556 11% /run
tmpfs tmpfs 4005240 0 4005240 0% /sys/fs/cgroup
/dev/sda1 xfs 508588 191684 316904 38% /boot
#是添加的磁盘生效
[root@VM-67-49 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1734656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=6938624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=3388, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 6938624 to 33162240
#验证
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 127G 9.4G 118G 8% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 395M 3.5G 11% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 497M 188M 310M 38% /boot
05-11 12:54