以 Aliyun ECS CentOS7 为例磁盘在线扩容
以阿里 ECS CentOS7 为例磁盘在线扩容
注; 请阅读文档,会有一些限制,如: kernel >= 3.6.0
- 操作过程
[root@cn-south1-web-1 ~]# lsblk
NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME
vda 0 512 0 512 512 1 mq-deadline 256 4096 0B
└─vda1 0 512 0 512 512 1 mq-deadline 256 4096 0B
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]# fdisk -lu
Disk /dev/vda: 80 GiB, 85899345920 bytes, 167772160 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
Disklabel type: dos
Disk identifier: 0x319ba3a3
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 125829086 125827039 60G 83 Linux
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs tmpfs 1.8G 620K 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/vda1 xfs 60G 59G 1.2G 99% /
tmpfs tmpfs 360M 0 360M 0% /run/user/0
overlay overlay 60G 59G 1.2G 99% /var/lib/docker/overlay2/67de133d9ad94c69e5748d7b702cc14bc63788687c38d566acd2bdafc7db42c8/merged
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#
# see: https://help.aliyun.com/document_detail/113316.html?spm=5176.11346930configuration.help.dexternal.37125ca3e9okwu#concept-syg-jxz-2hb
# CentOS7 及以上
[root@cn-south1-web-1 ~]# yum install -y cloud-utils-growpart
[root@cn-south1-web-1 ~]#
# 如果分区为GPT格式才用此命令
[root@cn-south1-web-1 ~]# yum install gdisk -y
[root@cn-south1-web-1 ~]#
# 执行扩容分区
[root@cn-south1-web-1 ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=125827039 end=125829087 new: size=167770079 end=167772127
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]# growpart /dev/vda 1
NOCHANGE: partition 1 is size 167770079. it cannot be grown
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#
# 扩容文件系统(如果是 ext4 文件系统才用此命令)
[root@cn-south1-web-1 ~]# resize2fs /dev/vda1
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#
# 扩容文件系统(如果是 xfs 文件系统才用此命令)
[root@cn-south1-web-1 ~]# xfs_growfs /dev/vda1
meta-data=/dev/vda1 isize=512 agcount=13, agsize=1310656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=15728379, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log 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 15728379 to 20971259
[root@cn-south1-web-1 ~]#
[root@cn-south1-web-1 ~]#