通过 LVM 对 CentOS 磁盘分区进行动态扩容
还是那堆联通云机,交付前 LVM 也不给搞好,云盘默认也不挂载,特别吐槽一下。怀念某云的傻瓜式服务,前者到底是国有,揍是硬气。
这是扩容前的情况:
[root@centos7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv 10G 10G 20K 100% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 369M 3.5G 10% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 485M 166M 319M 35% /boot
tmpfs 783M 0 783M 0% /run/user/0
用 vgs 和 lvs 看一下可用空间,并根据实际情况构造如下命令:
[root@centos7 ~]# lvresize -L +37.51G /dev/rootvg/rootlv
Rounding size to boundary between physical extents: 37.51 GiB.
Size of logical volume rootvg/rootlv changed from 10.00 GiB (2560 extents) to 47.51 GiB (12163 extents).
Logical volume rootvg/rootlv successfully resized.
最后同步一下文件系统就搞定了:
[root@centos7 ~]# xfs_growfs /dev/rootvg/rootlv
meta-data=/dev/mapper/rootvg-rootlv isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 2621440 to 12454912
验证:
[root@centos7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv 48G 9.8G 38G 21% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 369M 3.5G 10% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 485M 166M 319M 35% /boot
tmpfs 783M 0 783M 0% /run/user/0
自己马克一下。