All Products
Search
Document Center

:Extend partitions and file systems (Linux)

Last Updated:Aug 09, 2025

After you increase the capacity of a disk, the partitions and file systems on the disk are not automatically extended. You must manually extend the partitions and file systems to use the added capacity. This topic describes how to extend partitions and file systems for a disk on a Linux instance.

Note

If you already extended the partitions and file systems by using Cloud Assistant when you increased the disk capacity in the ECS console, you can skip this topic.

Prerequisites

  • The instance must meet the following conditions:

  • The disk must meet the following conditions:

    • The disk status is In Use.

    • The system disk usage is less than 100%.

      Important

      To ensure that the extension proceeds smoothly, log on to the instance and run the df -h command to confirm that the root partition usage is not 100%. If the root partition usage is 100%, see Resolve the issue of insufficient disk space on a Linux instance for solutions.

    • The file systems are mounted. For more information, see Mount a file system.

  • You have already increased the disk capacity but have not yet extended the partitions and file systems in the ECS console. For information about how to resize a disk, see Step 1: Resize a disk to extend its capacity.

    Note

    If you select Offline Resizing to resize a disk, you must restart the instance in the ECS console or by calling an API operation for the new disk size to take effect. For more information, see Restart an instance.

Preparations

  • (Strongly recommended) Create a snapshot of the disk to back up your data. For more information, see Create a snapshot.

    Note

    Although extending partitions and file systems does not typically cause data loss, we recommend that you create a snapshot to back up the disk data and prevent data loss from accidental operations.

  • Familiarize yourself with the disk resizing process. For more information, see Overview.

Method 1: Automatically extend partitions and file systems using Cloud Assistant (invitational preview)

Warning
  • This feature is in invitational preview and is available only to some customers.

  • The ECS instance must be in the Running status and have the Cloud Assistant Agent installed. For more information, see Install Cloud Assistant Agent. The Cloud Assistant Agent is installed by default on ECS instances that are created from public images after December 1, 2017.

If you accidentally close the page while using Cloud Assistant to extend partitions and file systems in Step 1: Increase disk capacity, you can navigate to the Block Storage tab on the instance details page to use Cloud Assistant again.

  1. Navigate to the interface for extending partitions and file systems using Cloud Assistant.

    1. On the Block Storage page of the instance details page, you can enable the Cloud Assistant detection feature.截屏2025-02-14 11

      Note

      This feature is in invitational preview and is available only to some customers. If you do not have the Cloud Assistant detection feature setting, see Method 2: Log on to the instance to manually extend the partition and file system.

    2. Select the disk whose partitions and file systems you want to extend. Hover over 2/3 Detection Passed under In-system Status Detection, and click Extend Partitions and File Systems. 截屏2025-01-17 09

      Note

      The Cloud Assistant-based disk capacity extension feature is available only for select operating systems. If the In-system Status Check column is not displayed, or if the In-system Status Check column displays Check failed, select Method 2: Log on to the instance and manually extend the partition and file system.

  2. Extend the partitions and file systems using Cloud Assistant.

    1. After entering the command to extend partitions and file systems, click Execute Remote Command.截屏2024-12-25 11

      Note

      If the command-line interface does not appear, you cannot use Cloud Assistant. In this case, select Method 2: Log on to the instance and manually extend partitions and file systems.

    2. In the Send Command dialog box, click Execute to automatically extend the partitions and file systems. The operation is complete when the status changes to Execution Succeeded.截屏2024-11-06 13

Method 2: Log on to the instance to extend partitions and file systems

If you cannot use Cloud Assistant to extend partitions and file systems in your environment, log on to the instance and use the command line to perform the extension.

Step 1: Record information about the disk to be extended

  1. Obtain the disk information.

    Method 1: Use the command line

    1. Connect to the ECS instance.

      Log on to the ECS console. In the navigation pane on the left, click Instances. On the Instances page, select the target instance and click Remote Connection. For more information, see Use Workbench to connect to a Linux instance over SSH.

    2. Run the following command to identify the name of the disk to be extended and its partitions.

      sudo fdisk -lu

      截屏2024-11-20 12

      1. Check if the disk is partitioned. The figure shows that the instance has three disks: system disk /dev/vda, data disk /dev/vdb, and data disk /dev/vdc. This example uses the data disks.

        • The name vdb1 indicates that the data disk /dev/vdb is partitioned. The number 1 is the partition number.

        • The name vdc indicates that the data disk /dev/vdc is not partitioned (it is a raw device).

      2. Identify the disk partition to extend. This example uses the data disk /dev/vdb.

        The SIZE column shows the capacity. In the figure, the capacity of the /dev/vdb1 partition is smaller than the capacity of the /dev/vdb disk. This means that the /dev/vdb1 partition needs to be extended.

        Note

        You can also run the lsblk command to check which partition needs to be extended.

      3. Identify the partition style of the disk. Disklabel type indicates the partition style of the disk. A value of dos indicates an MBR partition. A value of gpt indicates a GPT partition. This example uses the partitioned data disk /dev/vdb. The disk name is /dev/vdb, the partition name is /dev/vdb1, and the partition style is GPT.

        Note
        • The display varies slightly across operating systems. If the Disk label type field is not present, check the System field. A System value of Linux indicates an MBR partition. A value of GPT indicates a GPT partition.

        • Older versions of fdisk may not correctly display GPT partition tables. You can run the gdisk -l /dev/vdb command to view the partition style.

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

      sudo file -s raw_device_name/partition_name

      截屏2024-12-02 10

      The preceding example shows the following:

      The file system type of the /dev/vdb1 partition is ext4.

      The file system type of the unpartitioned raw device /dev/vdc is ext4.

      The unpartitioned raw device /dev/vdd has no file system.

      Note

      You can also run the sudo blkid command to obtain the file system information of the disk to be extended.

    Method 2: Use the console

    1. On the Block Storage tab of the instance details page, find the disk that you want to extend.

    2. Move the pointer over the content in the In-system information column to view the device name, partition style, partition name, file system type, and mount point of the disk. 截屏2025-01-22 09

      Note

      If the In-system Information column is not displayed or the In-system Information column is empty, you cannot use the Cloud Assistant query feature. In this case, see Method 1: Use the CLI.

  2. Determine which extension steps to perform.

    Note

    For specific extension examples, see Extension examples.

Step 2: Extend the partition

  1. If your disk is not partitioned but has a file system, proceed directly to Step 3: Extend the file system.

  2. Run the command to extend the partition.

    This section shows how to extend the /dev/vdb1 partition from 40 GiB to 60 GiB on an ECS instance. The disk capacity was already increased to 60 GiB in the console. Perform the operation based on your actual environment.

    Select a command to extend the specified partition based on the operating system and partition style.

    Alibaba Cloud Linux 2 or 3, CentOS 6 or later

    Important
    • CentOS 6 reached end of life (EOL). In accordance with Linux community rules, all content was removed from the following CentOS 6 repository address: http://mirror.centos.org/centos-6/. If you continue to use the default CentOS 6 repository on Alibaba Cloud, an error is reported. To use specific installation packages of CentOS 6, change the CentOS 6 repository address. For more information, see How do I change CentOS 6 repository addresses?

    • To extend a GPT partition table on CentOS 6, run the `parted` command. For more information, see Extend partitions and file systems on a data disk of a Linux instance offline. Do not run the `growpart` command. Otherwise, the partition table may be corrupted.

    • 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/vdb 1
    • GPT partition (requires the gdisk tool)

      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/vdb 1 

    Debian 9 or later, Ubuntu 14 or later

    Important

    Debian 9 and Debian 10 reached the EOL. If your instance runs Debian 9 or Debian 10, change the repository addresses of the operating system. For more information, see Change repository addresses after CentOS or Debian reached EOL (Integrated into corresponding operating systems).

    • MBR partition

      sudo apt-get update
      sudo apt-get install -y cloud-guest-utils
      sudo LC_ALL=en_US.UTF-8 growpart /dev/vdb 1
    • GPT partition (Requires installing the gdisk tool)

      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/vdb 1
    Important

    Note the following when you run the partition extension command:

    • If an error occurs when you use the growpart tool, see the FAQ for troubleshooting.

    • In the command parameters, add a space between /dev/vdb and 1. 1 is the partition number. Set these parameters as needed.

    • If you are extending a system disk, replace /dev/vdb with /dev/vda in the command.

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

    • If a disk has multiple consecutive partitions, you can extend only the last partition. For example, the data disk /dev/vdb has three partitions: /dev/vdb1, /dev/vdb2, and /dev/vdb3. You can extend only the last partition, /dev/vdb3. Run the growpart /dev/vdb 3 command to extend the partition on the data disk.

    • If you have an NVMe disk and the partition name is /dev/nvme0n1p1, the device name is /dev/nvme0n1. To extend the partition, run the growpart /dev/nvme0n1 1 command, not growpart /dev/nvme0n1p1 1.

    • If the partition that you want to extend is an extended partition in an MBR partition table (usually indicated by a partition number of 5 or greater), you must extend the extended partition first, and then extend the logical partition. For example, if you have three partitions, /dev/vdb1 (primary), /dev/vdb2 (extended), and /dev/vdb5 (logical), you must run growpart /dev/vdb 2 and then growpart /dev/vdb 5 to complete the partition extension.

    If the output includes the word CHANGED, as shown in the following figure, the partition was successfully extended.

    image.png

  3. Run the following command to check whether the partition was extended.

    sudo fdisk -lu

    截屏2024-11-20 14

    In the example shown in the figure, the capacity of /dev/vdb is the same as the capacity of /dev/vdb1. This indicates that the partition was successfully extended.

    Note

    For older operating systems such as CentOS 6, you must run the reboot command to restart the instance for the partition extension to take effect.

    Typically, you do not need to restart the instance after you extend a partition. However, if you extend a disk on a CentOS 6 operating system or find that the operating system does not recognize the extended partition after the extension, the cause is an old operating system version. You must restart the instance for the partition extension to take effect. Restart the instance during off-peak hours to avoid affecting your business.

Step 3: Extend the file system

Note
  • If you use Logical Volume Manager (LVM) to manage disk partitions, you must use LVM to extend the logical volumes (LVs) and the file systems after you resize a disk. For more information, see Extend an LV.

    How to check whether an LVM logical volume is used

    On the instance, run the following command:

    sudo lsblk

    Example output:

    NAME           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda            253:0    0   50G  0 disk 
    ├─vda1         253:1    0    2M  0 part 
    ├─vda2         253:2    0  200M  0 part /boot/efi
    └─vda3         253:3    0 49.8G  0 part /
    vdb            253:16   0   40G  0 disk 
    └─vdb1         253:17   0   40G  0 part 
      └─vg_01-lv01 252:0    0   40G  0 lvm

    If the output shows a partition with `lvm` as its `TYPE`, a logical volume is used. In the example output, /dev/vdb1 is used as a logical volume. Therefore, you must extend the physical volume and the logical volume before you extend the file system.

  • If the multi-attach feature is enabled for your disk and the disk uses a cluster file system, you must extend the cluster file system after you resize the disk. In this case, the procedure described in this topic is not applicable. Common cluster file systems include OCFS2, GFS2, Veritas CFS, Oracle ACFS, and DBFS. If you use standalone file systems, such as ext2, ext3, ext4, XFS (eXtensible File System), and NTFS (New Technology File System), data cannot be synchronized between the instances and data inconsistency may occur when the multi-attach feature is enabled for disks. For more information, see Enable the multi-attach feature for a cloud disk.

  1. Refer to Determine which extension steps to perform to confirm whether you need to extend the file systems on the disk.

  2. Run the following command to obtain the mount point of the device to be extended.

    df -Th

    The value of Type is the file system type. The value of Mounted on is the mount point of the partition. The following figure shows that the file system type of the /dev/vdb1 partition is ext4, and the mount point is /mnt.

    image.png

    If the value of Filesystem does not have a number as a suffix (for example, /dev/vdc), it is a raw device.

  3. Extend the file system.

    The extension command varies based on the file system type. Select one of the following commands based on the file system type that you identified in Step 1.

    Note

    If you use the resize2fs tool to extend a file system while the file system and its associated disk are in use, data issues may occur. These issues are related to the kernel version of the image and the version of the resize2fs tool, but not to the disk resize operation. We recommend that you create a snapshot of the disk to back up data in advance. For more information, see Create a snapshot.

    ext* (such as ext2, ext3, or ext4) file system

    • For example, to extend the ext* file system of the /dev/vdb1 partition, run the following command:

      sudo resize2fs /dev/vdb1
      Note

      If you are extending a system disk, replace /dev/vdb1 with /dev/vda1 in the command.

    • For example, to extend the ext* file system of the /dev/vdc raw device, run the following command:

      sudo resize2fs /dev/vdc

    xfs file system

    To extend the xfs file system that is mounted to the /mnt directory, run the following command:

    Alibaba Cloud Linux 2 or 3, CentOS 6 or later

    type xfs_growfs || sudo yum install -y xfsprogs
    sudo xfs_growfs /mnt

    Debian 8 or later, Ubuntu 14 or later

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

    btrfs file system

    To extend the btrfs file system that is mounted to the /mnt directory, run the following command:

    sudo btrfs filesystem resize max /mnt
  4. Run the following command to check whether the extension was successful.

    df -Th

    The extension is successful if the file system capacity in the query result matches the capacity in the console.

    The following figure shows that the file system capacity of the /dev/vdb1 partition (59 GiB) is almost the same as the disk capacity (60 GiB). This indicates that the extension is complete. The file system itself uses some storage space. image.png

    After the extension is complete, check whether the disk data is intact.

    • If the extension is successful and the applications on the ECS instance run as expected, the operation is complete.

    • If the file system sizes are not increased to the specified values, use the snapshots that you created to roll back the disk. For more information, see Roll back a disk using a snapshot.

Extension examples

This section provides command examples for extending an MBR partition, a GPT partition, and a raw data disk. These examples are for reference only. The commands that you use may vary based on your actual environment.

Example 1: Extend an MBR partition and an ext4 file system

  • Device name: /dev/vda (system disk)

  • 1 partition: /dev/vda1

  • File system type: ext4

  • Operating system: Alibaba Cloud Linux 3

The commands to extend the partition and file system are as follows:

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

Example 2: Extend a GPT partition and an xfs file system

  • Device name: /dev/vdb (data disk)

  • 2 partitions: /dev/vdb1 and /dev/vdb2

  • File system type: xfs

  • Mount directory of /dev/vdb2: /mnt

  • Operating system: Debian 12

The commands to extend the partition and file system are as follows:

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/vdb 2
type xfs_growfs || sudo apt-get install -y xfsprogs
sudo xfs_growfs /mnt

Example 3: Extend a raw data disk that has a file system

  • Device name: /dev/vdc (raw data disk, not partitioned)

  • File system type: ext4

  • Operating system: CentOS 7

The command to extend the file system is as follows:

sudo resize2fs /dev/vdc

FAQ

growpart issues

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

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

    Solution:

    • Run the locale command to check the character encoding of the ECS instance. If the character encoding is not en_US.UTF-8, change it to en_US.UTF-8.

      • Run the following command to change the character encoding.

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

        export LC_ALL=en_US.UTF-8
    • If the issue persists, try to run the reboot command to restart the ECS instance.

    Important

    After you successfully extend the partition by changing the character encoding, change it back to the original encoding if needed.

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

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

    Solution: Downgrade growpart to version 0.27. If the issue persists, perform the steps in the Extend partitions and file systems on a Linux data disk topic to extend the partition.

  • Issue 3: When I run the growpart command to extend a partition, the error message FAILED: unable to determine partition type appears.

    Cause: The disk is a raw device and is not partitioned. You do not need to extend the partition on a raw device. You only need to extend the file system.

    Solution: Perform the operations described in the Step 3: Extend the file system section of this topic.

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

    Cause: The MBR partition style does not support disks larger than 2 TiB.

    Solution: Convert the partition style of the disk from MBR to GPT before you extend the partitions on the disk. For more information, see Convert MBR partitions into GPT partitions.

  • Issue 5: When I run the growpart command to extend a partition, the error message mkdir: cannot create directory ... No space left on device appears.

    Cause: The disk space is insufficient, which caused the growpart command to fail when it tried to create a temporary directory.

    Solution: Delete unnecessary files to free up space, and then perform the extension. For more information, see Resolve the issue of insufficient disk space on a Linux instance.

  • Issue 6: When I install the growpart tool in CentOS 6, the error message Error: Cannot retrieve repository metadata appears.

    Cause: The CentOS 6 operating system has reached its EOL. If you continue to use the default repository, package installation fails.

    Solution:

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

    Cause: A device name that starts with /dev/mapper usually indicates that LVM is used to manage the disk partitions.

    Solution: Use LVM to extend the LVs and then extend the file systems. For more information, see Extend an LV.

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

    Cause: There is no free space to extend the partition. This issue usually occurs because after you extend the disk offline in the console, you do not restart the instance from the console or using an API operation. As a result, the disk itself is not extended.

    Solution: After you extend a disk offline, you must restart the instance in the ECS console or by calling an API operation for the new disk size to take effect. If you run the reboot command from within the instance, the new disk size does not take effect. For more information, see Restart an instance or RebootInstance.

resize2fs issues

Common issues when you run the resize2fs command

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

    Cause: When you extend a file system, you must specify the disk partition name, not the device name or mount point.

    Solution: Specify the correct partition name.

  • When I run the resize2fs command to extend a file system, the error message The filesystem is already ... blocks long. Nothing to do! appears.

    Cause: The file system has no space to extend. This may be because the partition was not extended or the extension has not taken effect.

    Solution:

    1. First, confirm that you have successfully extended the partition using the growpart command. If you missed this step, run the growpart command to extend the partition.

    2. If you successfully ran the growpart command to extend the partition, the operating system version may be too old to update the system partition table online. Try to restart the instance, and then run the resize2fs command.

  • When I run the resize2fs command to extend a file system, the error message resize2fs: Permission denied to resize filesystem appears.

    Cause: The file system itself may be inconsistent and contain errors, which caused the file system extension to fail.

    Solution:

    1. 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.

    2. Create a snapshot to back up your disk.

    3. If your business allows, run the umount command to unmount the mounted partition or the entire disk as needed.

      If it is a system disk, which cannot be unmounted using the umount command, you must detach the system disk and attach it to another instance to perform the repair.
    4. Try to use the e2fsck command to repair the file system.

  • When I run the resize2fs command to extend a file system, the error message inodes (4294967296) must be less than 4294967295 appears.

    Cause: The bytes-per-inode parameter was not correctly set during initialization.

    To extend a disk to 64 TiB, you must add -i 65536 to the command when you create the file system.

    Solution: Create a new disk and copy the data.

    Important

    The bytes-per-inode parameter cannot be changed after the disk is initialized.

    1. For the current instance, create an empty data disk with the target capacity.

    2. When you initialize a data disk and create an ext4 file system, add -i 65536 to the command.

    3. Manually copy the data from the source disk to the new disk.

    4. Verify that your services are restored. After the operation is complete, restart the related services and check whether your services run as expected.

    5. After you confirm that your services are running as expected, you can uninstall the original data disk and then release it. For more information, see Uninstall a data disk and Release a disk.

Cloud Assistant detection issues

The In-system status detection shows Detection failed

The Cloud Assistant detection feature is supported on only some 64-bit x86 operating systems to view disk information in the system:

  • Alibaba Cloud Linux 2 and 3

  • AlmaLinux 8.x and later

  • CentOS 7.x and 8.x

  • CentOS Stream 8 and later

  • Fedora 33 and later

  • Debian 8.x and later

    Note

    For Debian 8, 9, 10, and 11, you must run the sudo apt-get install parted command in the system to install the parted tool before you can use the Cloud Assistant detection feature.

  • OpenSUSE 15.x and 42.x

  • SUSE Linux Enterprise Server 12.x and 15.x

  • Ubuntu 16.04, 18.04, 20.04, 22.04, and 24.04

  • Rocky Linux 8.x and later

  • Anolis OS 7.x and 8.x