分区扩容有两种方法:
1、添加新硬盘
2、从其他分区拿空闲空间,本次演示这种
查看vgdisplay剩余空间
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <119.00 GiB
PE Size 4.00 MiB
Total PE 30463
Alloc PE / Size 30462 / 118.99 GiB
Free PE / Size 1 / 4.00 MiB 空闲空间
VG UUID uDLmZJ-lh3c-belC-VASm-p26Y-T7VQ-LlcGxq
备份home目录
[root@localhost /]# tar -czvf home.tar.gz home
卸载home分区
[root@localhost /]# umount /home/
将home的lv空间减小21G
[root@localhost /]# lvreduce -L -21G /dev/mapper/centos-home
WARNING: Reducing active logical volume to 45.24 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/home? [y/n]: y
Size of logical volume centos/home changed from 66.24 GiB (16958 extents) to 45.24 GiB (11582 extents).
Logical volume centos/home successfully resized.
格式化分区
[root@localhost /]# mkfs.xfs /dev/mapper/centos-home -f
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=2964992 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=11859968, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5791, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
重新挂载home分区
[root@localhost /]# mount /dev/mapper/centos-home /home
解压home.tar.gz
[root@localhost /]# pwd
/
[root@localhost /]# tar -zxvf home.tar.gz
将空闲空间给root分区
lvextend -L +21G /dev/mapper/centos-root
或
lvextend -L +100%FIEE /dev/mapper/centos-root
[root@localhost /]# lvextend -L +21G /dev/mapper/centos-root 或lvextend -L +100%FIRE /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 71.00 GiB (18176 extents).
Logical volume centos/root successfully resized.
使用xfs_growfs命令刷新文件系统使用空间转移生效
注:xfs_growfs此命令只可增加,不能用于减小
[root@localhost /]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 18612224
查看结果
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 657M 0 657M 0% /dev
tmpfs 668M 0 668M 0% /dev/shm
tmpfs 668M 9.3M 659M 2% /run
tmpfs 668M 0 668M 0% /sys/fs/cgroup
/dev/mapper/centos-root 71G 2.0G 69G 3% /
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 134M 0 134M 0% /run/user/0
/dev/mapper/centos-home 46G 33M 46G 1% /home
参与文档
Centos 7.5利用LVM实现动态扩容大小
https://blog.csdn.net/u010735147/article/details/84254926
centos7下使用LVM给系统硬盘扩容超详细
https://www.cnblogs.com/ding2016/p/9680690.html
------------------end