This topic describes how to use the growpart and resize2fs tools to resize partitions
and file systems of Linux system disks.
Prerequisites
Before you resize partitions and file systems of system disks, make sure that the
following requirements are met:
- A snapshot is created to back up data.
To prevent data loss caused by incorrect operations, we recommend that you create
a snapshot to back up your data. For more information, see Create a normal snapshot.
- A data disk is resized in the console.
If no data disks are resized, see Resize disks online for Linux instances or Resize disks offline for Linux instances to resize a data disk.
- Remotely connect to an ECS instance. For more information, see Overview.
- The growpart or xfsprogs tool is installed based on your operating system.
- Alibaba Cloud Linux 2 and CentOS 7:
Run the yum install <Package name>
command to install the tools.
yum install cloud-utils-growpart xfsprogs -y
- Ubuntu 14, Ubuntu 16, Ubuntu 18, and Debian 9:
Run the apt install <Package name>
command to install the tools.
apt install cloud-guest-utils xfsprogs -y
- Debian 8, openSUSE 42.3, openSUSE 13.1, and SUSE Linux Enterprise Server 12 SP2:
Use the upstream version of the growpart or xfsprogs tool.
Note If the partition or file system fails to be resized due to an error on the growpart
or xfsprogs tool, we recommend that you re-install the tool.
- Run the
uname -a
command to check the kernel version of the instance operating system.
Background information
The procedures in this topic apply to disks that have the following partition formats
and file system types:
- Partition formats: MBR and GPT
- File system types: ext*, XFS, and Btrfs
Procedure for instances with kernels 3.6.0 or later
Alibaba Cloud Linux 2.1903 LTS 64-bit is used in this example to describe how to resize
partitions and file systems.
Note The commands used in the following examples also apply to CentOS 7.
- Run the following command to check the size of the existing disk:
fdisk -l
In the following example command output, the size of the
/dev/vda disk is 100 GiB:
[root@ecshost ~]# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000bad2b
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999 83 Linux
- Run the following command to check the size of the partition and the type of the file
system:
df -Th
In the following example command output, the size of the
/dev/vda1 partition is 40 GiB, and the type of the file system is ext4:
[root@ecshost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 869M 0 869M 0% /dev
tmpfs tmpfs 879M 0 879M 0% /dev/shm
tmpfs tmpfs 879M 460K 878M 1% /run
tmpfs tmpfs 879M 0 879M 0% /sys/fs/cgroup
/dev/vda1 ext4 40G 1.8G 36G 5% /
tmpfs tmpfs 176M 0 176M 0% /run/user/0
- Run the following command to resize partitions:
growpart <DeviceName> <PartionNumber>
In the following example command output, the first partition
/dev/vda1 of the system disk is resized:
[root@ecshost ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=83883999 end=83886047 new: size=209713119 end=209715167
Note If the
unexpected output in sfdisk --version [sfdisk, from util-linux 2.23.2]
error is prompted when the
growpart /dev/vda 1
command is run, try to change the character encoding to fix the problem. For more
information, see
FAQ.
- Resize the file system.
Use the
df -Th
command to check the type of the file system. Then, select one of the following methods
to resize the file system based on the type of the file system:
- If the type of the file system is ext* such as ext3 and ext4, run the following command
to resize the file system:
resize2fs <PartitionName>
In the following example, the file system of the
/dev/vda1 partition is resized:
[root@ecshost ~]# resize2fs /dev/vda1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 7
The filesystem on /dev/vda1 is now 26214139 blocks long.
- If the type of the file system is XFS, run the following command to resize the file
system:
xfs_growfs <mountpoint>
In the following example, the file system of the /dev/vda1 partition is resized. The mount point of the /dev/vda1 partition is the / root directory.
[root@ecshost ~]# xfs_growfs /
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
Note The commands may vary depending on versions of the xfs_growfs tool. Run xfs_growfs --help
to check the corresponding commands.
- Run the following command to check the size of the disk partition:
df -h
The following example shows that the size of the
/dev/vda1 partition is 100 GiB. This indicates that the partition is resized.
[root@ecshost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 869M 0 869M 0% /dev
tmpfs 879M 0 879M 0% /dev/shm
tmpfs 879M 492K 878M 1% /run
tmpfs 879M 0 879M 0% /sys/fs/cgroup
/dev/vda1 99G 1.8G 93G 2% /
tmpfs 176M 0 176M 0% /run/user/0
Procedure for instances with kernels earlier than 3.6.0
CentOS 6 is used in this example to describe how to resize partitions and file systems.
Note CentOS 6 has reached its end of life (EOL). To install the software package of CentOS
6, you must temporarily change the CentOS 6 software source address. For more information,
see
Change the CentOS 6 source address.
- Run the following command to install the dracut-modules-growroot tool:
yum install -y dracut-modules-growroot
Note If a package manager other than YUM is used, change yum in the preceding command based on the package manager.
- Run the following command to overwrite the existing initramfs file:
- Run the following command to check the size of the existing disk:
fdisk -l
In the following example, the size of the
/dev/vda disk is 100 GiB:
[root@ecshost ~]# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003a7b4
Device Boot Start End Blocks Id System
/dev/vda1 * 1 2611 20970496 83 Linux
- Run the following command to check the size of the partition and the type of the file
system:
df -Th
The following example shows that the size of the
/dev/vda1 partition is 20 GiB, and the type of the file system is ext4:
[root@ecshost ~]# df -h
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 20G 1.1G 18G 6% /
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
- Run the following command to resize the partition:
growpart <DeviceName> <PartionNumber>
The following example shows that the first partition
/dev/vda1 of the system disk is resized:
[root@ecshost ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=41940992 end=41943040 new: size=209710462,end=209712510
- Restart the instance in the ECS console.
Notice The resizing operation does not take effect until you restart the instance by using
the console or calling the
RebootInstance operation. For more information, see
Restart an instance and
RebootInstance.
- Connect to the instance.
- Resize the file system.
Use the
df -h
command to check the type of the file system. Then, use one of the following methods
to resize the file system based on the type of the file system:
- If the type of the file system is ext* such as ext3 and ext4, run the following command
to resize the file system:
resize2fs <PartitionName>
The following example shows that the file system of the
/dev/vda1 partition is resized:
[root@ecshost ~]# resize2fs /dev/vda1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 7
Performing an on-line resize of /dev/vda1 to 26213807 (4k) blocks.
The filesystem on /dev/vda1 is now 26213807 blocks long.
- If the type of the file system is XFS, run the following command to resize the file
system:
xfs_growfs <mountpoint>
The following example shows that the file system of the /dev/vda1 partition is resized. The mount point of the /dev/vda1 partition is the / root directory.
[root@ecshost ~]# xfs_growfs /
Note The commands may vary depending on versions of the xfs_growfs tool. Run xfs_growfs --help
to check the corresponding commands.
- Run the following command to check the size of the disk partition:
df -h
The following example shows that the size of the
/dev/vda1 partition is 100 GiB. This indicates that the partition is resized.
[root@ecshost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 1.1G 93G 2% /
tmpfs 7.8G 0 7.8G 0% /dev/shm