示例说明:
数据盘 /dev/vdb
原有容量100GiB,只有一个分区 /dev/vdb1
。将数据盘容量扩大至150GiB,将新增的50GB增加至已有分区 /dev/vdb1
。
1. 检查当前系统是否已安装growpart扩容工具。
growpart
- 如果回显为工具使用介绍,则表示已安装,无需重复安装。
[root@ecs-centos76 ~]# growpart
growpart disk partition
rewrite partition table so that partition takes up all the space it can
options:
-h | --help print Usage and exit
--fudge F if part could be resized, but change would be
less than 'F' bytes, do not resize (def ault: 1048576)
-N | --dry-run only report what would be done, show new 'sfdisk -d'
-v | --verbose increase verbosity / debug
-u | --update R update the the kernel partition table info after growing
this requires kernel support and 'partx --update'
R is one of:
- 'auto': [default] update partition if possible
- 'force' : try despite- sanity checks (fail on failure)
- 'off' : do not attempt
- 'on' : fail if sanity checks indicate no support
Example:
- growpart /dev/sda 1
Resize partition 1 on /dev/sda
must supply disk and part it ion-number
[root@ecs-centos76 ~l#
- 如果没有以上回显信息,请执行以下安装命令。
apt install cloud-utils-growpart
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/x86_64/metalink
| 8.0 kB 00:00:00
...
Package cloud-utils-growpart-0.29-2.el7.noarch already installed and latest version
Nothing to do
表示安装成功。
2. 查看数据盘“/dev/vdb”的分区信息。
lsblk
[root@ecs-centos76 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
├vda1 253:1 0 40G 0 part /
vdb 253:16 0 150G 0 disk
├vdb1 253:17 0 100G 0 part /mnt/sdc
表示数据盘“/dev/vdb”有150GiB的容量,分区“/dev/vdb1”已有100GiB,扩容的50GiB容量还未划分磁盘分区。
如果磁盘未分区,需要直接扩容文件系统,请执行4。
3. 将扩容新增的容量增加至分区“/dev/vdb1”。
growpart /dev/vdb 1
[root@ecs-test-0001 ~]# growpart /dev/vdb 1
CHANGED: partition=1 start=2048 old: size=209713152 end=209715200 new: size=314570719,end=314572767
4. 扩容分区“/dev/vdb1”文件系统大小。
-
查看数据盘
/dev/vdb
对应分区/dev/vdb1
的文件系统类型。
parted /dev/vdbP
[root@ecs-centos74 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049KB 107GB 107GB ext4 /dev/vdb1 (parted)
查看完成后,输入“q”,按“Enter”,退出parted模式。
-
根据回显可知分区
/dev/vdb1
的文件系统类型为ext4,执行以下命令进行扩容。
resize2fs /dev/vdb1[root@ecs-test-0001 ~]# resize2fs /dev/vdb1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/vdb1 is mounted on /mnt/sdc; on-line resizing required old_desc_blocks = 13, new_desc_blocks = 19 The filesystem on /dev/vdb1 is now 39321339 blocks long.
5. 查看扩容后分区的容量。
lsblk
[root@ecs-centos76 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
├vda1 253:1 0 40G 0 part /
vdb 253:16 0 150G 0 disk
├vdb1 253:17 0 150G 0 part /mnt/sdc
表示数据盘“/dev/vdb”的容量大小为150GiB,该数据盘下的分区“/dev/vdb1”大小也为150GiB,说明扩容的50GB容量已生效。