All Products
Search
Document Center

:Step 2: Expand partitions and file systems

Last Updated:Aug 11, 2025

After you expand the capacity of a disk, you must also expand its partitions and file systems. This process allocates the newly added capacity to existing partitions and file systems, which allows the operating system to use the additional space. This topic describes how to expand the partitions and file systems of a disk for an RDS Custom instance.

Prerequisites

  • The RDS Custom instance meets the following requirements:

    • The status is Running.

    • The operating system is Alibaba Cloud Linux 2/3, CentOS 7 or later, Debian 11 or later, or Ubuntu 14 or later.

  • The disk meets the following requirements:

    • The status is In Use.

    • The usage of the system disk is less than 100%.

      Important

      To ensure a successful expansion, log on to the instance and run the df -h command to confirm that the root partition usage is less than 100%.

  • You have expanded the disk capacity but have not expanded the partitions and file systems.

Precautions

We strongly recommend that you create a snapshot for the disk to back up data before you expand the disk.

Note

Expanding partitions and file systems does not cause data loss. However, to prevent data loss from accidental misoperations, we recommend that you create a snapshot to back up the disk data.

Procedure

Step 1: View the information about the disk to be expanded and confirm the expansion steps

  1. Connect to the RDS Custom instance.

  2. Run the following command to view the name of the disk to be expanded and its partition information.

    sudo fdisk -lu

    image

    1. Check whether the disk is partitioned. In the preceding figure, the instance has three disks: the system disk /dev/nvme0n1, and two data disks, /dev/nvme1n1 and /dev/nvme2n1. The data disks are used as an example:

      • The data disk /dev/nvme1n1 is partitioned and has the /dev/nvme1n1p1 partition.

      • The data disk /dev/nvme2n1 is not partitioned (it is a raw device).

    2. Determine the partition type of the disk. The Disklabel type field indicates the partition type. A value of gpt indicates GUID Partition Table (GPT), and a value of dos indicates Master Boot Record (MBR). In this example, the disk uses the GPT partition type.

  3. Run the following command to obtain the file system information of the disk to be expanded.

    • For an unpartitioned disk

      sudo file -s /dev/raw_device_name
    • For a partitioned disk

      sudo file -s /dev/partition_name

    Take the /dev/nvme1n1p1 partition as an example. Run the following command.

    sudo file -s /dev/nvme1n1p1
    • If the following result is returned, the file system of the /dev/nvme1n1p1 partition is ext4.

      /dev/nvme1n1p1: Linux rev 1.0 ext4 filesystem data, UUID=342527ce-**** (needs journal recovery) (extents) (64bit) (large files) (huge files)
    • If /dev/nvme1n1p1: data is returned, the partition does not have a file system.

  4. Confirm the expansion steps to be performed.

Step 2: Expand the partition

If the disk is not partitioned but has a file system, you do not need to expand the partition. You can directly perform Step 3: Expand the file system.

  1. Run the following command to expand the partition. This example uses the /dev/nvme1n1p1 partition. /dev/nvme1n1 is the disk name, and 1 in p1 is the partition number. A space is required between the disk name and the partition number. Replace the disk name and partition number in the command with your actual values.

    Alibaba Cloud Linux 2/3, CentOS 7 and later

    • GPT partition (The gdisk tool is required.)

      type growpart || sudo yum install -y cloud-utils-growpart
      sudo yum update cloud-utils-growpart
      type sgdisk || sudo yum install -y gdisk
      sudo LC_ALL=en_US.UTF-8 growpart /dev/nvme1n1 1 
    • MBR partition

      type growpart || sudo yum install -y cloud-utils-growpart
      sudo yum update cloud-utils-growpart
      sudo LC_ALL=en_US.UTF-8 growpart /dev/nvme1n1 1

    Debian 11 and later, Ubuntu 14 and later

    • GPT partition (The gdisk tool is required.)

      sudo apt-get update
      sudo apt-get install -y cloud-guest-utils
      type sgdisk || sudo apt-get install -y gdisk
      sudo LC_ALL=en_US.UTF-8 growpart /dev/nvme1n1 1
    • MBR partition

      sudo apt-get update
      sudo apt-get install -y cloud-guest-utils
      sudo LC_ALL=en_US.UTF-8 growpart /dev/nvme1n1 1
    Important
    • For an NVMe disk, take the /dev/nvme1n1p1 partition as an example. /dev/nvme1n1 is the disk name, and 1 in p1 is the partition number. A space is required between the disk name and the partition number. To expand the partition, run the growpart /dev/nvme1n1 1 command.

    • For a virtual disk, take the /dev/vdb1 partition as an example. /dev/vdb is the disk name, and 1 is the partition number. A space is required between the disk name and the partition number. The expansion command is growpart /dev/vdb 1

    • LC_ALL=en_US.UTF-8 is an environment variable setting that ensures compatibility with the character encoding of Chinese operating systems.

    • If a disk has multiple consecutive partitions, you can expand only the last partition. For example, the data disk /dev/nvme3n1 has three partitions: /dev/nvme3n1p1, /dev/nvme3n1p2, and /dev/nvme3n1p3. You can expand only the last partition /dev/nvme3n1p3. To expand the partition of the data disk, run the growpart /dev/nvme3n1 3 command.

    • If the disk partition that you want to expand is an extended partition in an MBR partitioned table (the partition number is usually 5 or greater), you must expand the extended partition before you expand the logical partition. For example, if you have three partitions, /dev/nvme1n1p1 (primary partition), /dev/nvme1n1p2 (extended partition), and /dev/nvme1n1p5 (logical partition), you must run growpart /dev/nvme1n1 2 and then growpart /dev/nvme1n1 5 to expand the partitions.

    If a message that contains CHANGED is returned, the partition is expanded.

    CHANGED: partition=1 start=2048 old: size=41938944 end=41940991 new: size=52426719 end=52428766
  2. Run the following command to check whether the partition is expanded.

    sudo fdisk -lu

    Take the expansion of the /dev/nvme1n1p1 partition as an example. If the capacity of the /dev/nvme1n1p1 partition is the same as the capacity of the /dev/nvme1n1 disk, the partition is successfully expanded.

    image

Step 3: Expand the file system

  1. Run the following command to obtain the mount directory of the device to be expanded.

    df -Th

    image

    The value of Type is the file system type. The value of Mounted on is the mount directory of the partition. For example:

    • The file system of the /dev/nvme2n1 disk is ext4, and the mount directory is /tmp.

    • The file system of the /dev/nvme1n1p1 partition is ext4, and the mount directory is /mnt.

    Note

    If the value of Filesystem is a disk name, such as nvme2n1, the destination disk is not partitioned and is a raw device. If the value is a partition name, such as /dev/nvme1n1p1, the destination disk is partitioned.

  2. Run the following command to expand the file system.

    ext* (such as ext2, ext3, and ext4) file systems

    • For an unpartitioned disk, such as the /dev/nvme2n1 disk.

      sudo resize2fs /dev/nvme2n1
    • For example, /dev/nvme1n1p1 is a disk partition.

      sudo resize2fs /dev/nvme1n1p1

    xfs file systems

    Take the expansion of an xfs file system whose mount directory is /mnt as an example. Replace the mount directory in the command as needed.

    • Alibaba Cloud Linux 2/3, CentOS 7 and later

      type xfs_growfs || sudo yum install -y xfsprogs
      sudo xfs_growfs /mnt
    • Debian 11 and later, Ubuntu 14 and later

      type xfs_growfs || sudo apt-get install -y xfsprogs
      sudo xfs_growfs /mnt

    btrfs file systems

    Take the expansion of a btrfs file system whose mount directory is /mnt as an example. Replace the mount directory in the command as needed.

    sudo btrfs filesystem resize max /mnt
  3. Run the df -Th command to check whether the expansion is successful.

    For example, the disk that contains the /dev/nvme1n1p1 partition is expanded to 25 GiB. After the file system is expanded, its capacity is also 25 GiB.

    Note

    Because a file system occupies a specific amount of storage space, the free space of the file system may be slightly smaller than the total capacity of the expanded disk.

FAQ

growpart-related issues

  • Question 1: When I run the growpart command to expand a partition, the unexpected output in sfdisk --version [sfdisk, from util-linux 2.23.2] error message is reported.

    Cause: The Chinese operating system uses a character encoding type other than en_US.UTF-8.

    Solutions:

    • Run the locale command to check the character encoding type of the RDS Custom instance, and switch any character encoding type other than en_US.UTF-8 to en_US.UTF-8.

      • Run the following command to switch the character encoding type.

        export LANG=en_US.UTF-8
      • If the issue persists, run the following command to switch the character encoding type.

        export LC_ALL=en_US.UTF-8
    • If the issue persists, try to restart the RDS Custom instance.

    Important

    After you switch the character encoding and successfully expand the partition, we recommend that you switch back to the original character encoding type as needed.

  • Question 2: When I run the growpart command to expand a partition, the unexpected output in sfdisk --version [sfdisk (util-linux-ng 2.17.2)] error message is reported.

    Cause: The version of fdisk is not compatible with the version of growpart.

    Solution: Try to downgrade the growpart version to 0.27. If the issue persists, see Expand partitions and file systems for a Linux data disk to expand the partition.

  • Question 3: When I run the growpart command to expand a partition, the FAILED: unable to determine partition type error message is reported.

    Cause: Your disk is a raw device and is not partitioned. You do not need to expand the partition for a raw device. You can directly expand the file system.

    Solution: Directly perform Step 3: Expand the file system.

  • Question 4: When I run the growpart command to expand a partition, the WARNING: MBR/dos partitioned disk is larger than 2TB. Additional space will go unused. error message is reported.

    Cause: The MBR partition type does not support disks that are larger than 2 TiB.

    Solution: Convert the partition type from MBR to GPT, and then expand the partition. For more information, see Convert an MBR partition to a GPT partition.

  • Question 5: When I run the growpart command to expand a partition, the mkdir: cannot create directory ... No space left on device error message is reported.

    Cause: The growpart command fails to create a temporary folder because the disk space is insufficient.

    Solution: Expand the disk capacity.

  • Question 7: A partition whose device name starts with /dev/mapper fails to be expanded.

    Cause: A device name that starts with /dev/mapper indicates that the disk partition is managed by Logical Volume Manager (LVM).

    Solution: You must use LVM to expand the logical volume, and then expand the file system. For more information, see Use LVM to expand a logical volume.

  • Question 8: When I run the growpart command to expand a partition, the NOCHANGE: partition 1 could only be grown by 2015 [fudge=2048] error message is reported.

    Cause: No free space is available for partition expansion. This issue usually occurs because after you expand the disk offline in the console, you do not restart the instance in the console or using OpenAPI. As a result, the disk expansion does not take effect.

    Solution: After you expand the disk offline, you must restart the instance to make the disk expansion take effect. For more information, see Restart an instance.

resize2fs-related issues

  • Question 1: When I run the resize2fs command to expand a file system, the Couldn't find valid filesystem superblock. or open: Is a directory while opening /mnt error message is reported.

    Cause: When you expand a file system using resize2fs, you must specify the disk partition name, not the disk device name or the mount directory.

    Solution: When you expand a file system, specify the correct partition name.

  • Question 2: When I run the resize2fs command to expand a file system, the The filesystem is already ... blocks long. Nothing to do! error message is reported.

    Cause: The file system has no space to expand. This may be because the partition is not expanded or the expansion does not take effect.

    Solutions:

    • Check whether you have successfully performed the step of using growpart to expand the partition. If not, run the growpart command to expand the partition.

    • If you have run the growpart command and the CHANGED message was returned, but you still receive the error when you run the resize2fs command, the cause may be that your operating system is an older version that cannot update the system partition table online. In this case, run the reboot command to restart the instance, and then run the resize2fs command again.

  • Question 3: When I run the resize2fs command to expand a file system, the resize2fs: Permission denied to resize filesystem error message is reported.

    Cause: The file system expansion may fail because the file system is inconsistent.

    Solutions:

    • Run the dmesg -T | grep fs command. If a message such as There are errors in the filesystem is returned, the file system is inconsistent.

    • Back up the disk data. For more information, see Create a snapshot.

    • Try to use the e2fsck command to repair the file system. For information about how to use the e2fsck command, see its manual.

References

Introduction to ApsaraDB RDS Custom