本文将介绍阿里云在Linux环境下如何对云盘根分区进行扩容。

安装软件

CentOS 7、Aliyun Linux:

1
yum install cloud-utils-growpart xfsprogs -y

Ubuntu:

1
apt install cloud-guest-utils xfsprogs -y

执行扩容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
growpart /dev/vda 1

命令查看文件系统类型
df -Th

ext*文件系统(例如ext3和ext4)
resize2fs /dev/vda1

xfs文件系统
xfs_growfs /

详细步骤:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@test history]# fdisk -l
Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000d2717
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   209713151   104855552   83  Linux
[root@test history]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        99G   89G  4.7G  95% /
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
tmpfs            16G  520K   16G   1% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
tmpfs           3.2G     0  3.2G   0% /run/user/0
tmpfs           3.2G     0  3.2G   0% /run/user/1000
[root@test history]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=209711104 end=209713152 new: size=419428319 end=419430367
[suadm@izwz96eo65uiwiky72l3mbz history]# resize2fs /dev/vda1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 13
The filesystem on /dev/vda1 is now 52428539 blocks long.
[root@izwz96eo65uiwiky72l3mbz history]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       197G   89G  100G  48% /
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
tmpfs            16G  520K   16G   1% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
tmpfs           3.2G     0  3.2G   0% /run/user/0
tmpfs           3.2G     0  3.2G   0% /run/user/1000
[root@test history]#

参考文章:

扩容分区和文件系统(Linux系统盘)