All Products
Search
Document Center

Elastic Compute Service:Extend the partitions and file systems of disks on a Linux instance

Last Updated:Apr 23, 2025

After you resize a disk attached to an Elastic Compute Service (ECS) instance, the partitions and file systems on the disk are not automatically extended together with the disk. You must manually extend the partitions and file systems on the disk to use the added disk space. This topic describes how to extend partitions and file systems on a disk attached to a Linux ECS instance.

Note

If you have extended the partitions and file systems by using Cloud Assistant when you extended the cloud disk capacity in the ECS console, you do not need to perform operations described in this topic.

Prerequisites

  • An ECS instance meets the following requirements:

    • The instance is in the Running (Running) state.

    • The instance runs one of the following operating systems: Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 6 or later, Debian 8 or later, or Ubuntu 14 or later.

      Important
  • A disk meets the following requirements:

    • The disk is attached to the preceding ECS instance and is in the In Use (In_use) state.

    • The usage of the system disk attached to the ECS instance is lower than 100%.

      Important

      You can perform the Extend operation on disks attached to an ECS instance only if the usage of the system disk attached to the instance is lower than 100%. Log on to the ECS instance and run the df -h command to check whether the usage of the root partition reached 100%. If the usage of the root partition reached 100%, troubleshoot the issue. For more information, see Resolve the issue of insufficient disk space on a Linux instance.

    • File systems are mounted. For information about how to mount file systems, see the Step 3: Create and mount file systems section of the "Initialize a data disk on a Linux instance" topic.

  • You already resize the cloud disk capacity but do not extend 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 the disk capacity.

    Note

    If you set the Resizing Method parameter to Offline Resizing when you resize a disk that is attached to an ECS instance, you must restart the instance in the ECS console or by calling an API operation after you resize the disk to make the new disk size take effect. For more information, see Restart an instance.

Preparations

  • (Recommended) You create a snapshot for the disk whose partitions and file systems you want to extend to back up disk data. For more information, see Create a snapshot.

    Note

    In most cases, extending partitions and file systems does not cause data loss. To prevent data loss or exceptions caused by accidental operations, we recommend that you create snapshots to back up disk data.

  • You must be familiar with the process for resizing a disk. For more information, see Overview.

Method 1: Use Cloud Assistant to automatically extend the partitions and file systems of a disk (Invitational Preview)

Warning
  • This feature is in invitational preview and accessible only to specific users.

  • The disk is in the Running state and on which Cloud Assistant Agent is installed. By default, Cloud Assistant Agent is pre-installed on ECS instances that are created from public images on or after December 1, 2017. For more information, see Install Cloud Assistant Agent.

If you accidentally close the page when you configure parameters on the Use Cloud Assistant tab in Step 1: Resize a disk to extend the disk capacity, go to the Block Storage tab of the instance details page and use Cloud Assistant to extend partitions and file systems.

  1. Click the Use Cloud Assistant tab on the Expand Partitions and File Systems page.

    1. On the Block Storage tab of the instance details page, enable the Cloud Assistant check feature. 截屏2024-11-18 11

      Note

      This feature is in invitational preview and accessible only to specific users. If the Cloud Assistant Check setting does not appear, select Method 2: Log on to the instance and extend the partitions and file systems on a disk.

    2. Select the disk whose partitions and file systems you want to extend. Move the pointer over 2/3 Check Passed in the In-system Status Check column and click Extend Partitions and File Systems. 截屏2025-01-17 09

      Note

      Only specific operating system supports the Cloud Assistant-based disk capacity extension feature. If the In-system Status Check column does not appear or the In-system Status Check column displays that the check fails, select Method 2: Log on to the instance and extend the partitions and file systems on a disk.

  2. Use Cloud Assistant to extend partitions and file systems.

    1. Click Run Preceding Command in the lower part of the Command Content section to extend the partitions and file systems.截屏2024-12-25 11

      Note

      If the CLI does not appear, you cannot use the Cloud Assistant query feature. In this case, select Method 2: Log on to the instance and extend the partitions and file systems on a disk.

    2. In the Send Remote Commands dialog box, click Run. The system runs the commands on the instance to extend the partitions and file systems of the disk. If Normal is displayed in the Status column, the partitions and file systems of the disk are extended.截屏2024-11-06 13

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

If you cannot use Cloud Assistant to extend partitions or file systems on a disk attached to an ECS instance, you can log on to the instance and run commands to extend the partitions and file systems.

Step 1: Obtain disk information

  1. Obtain disk information.

    Method 1: Use the CLI

    1. Connect to a Linux ECS instance.

      Log on to the ECS console. In the left-side navigation pane, click Instances. On the Instance page, find the Linux ECS instance to which you want to connect and click Connect in the Actions column. For more information, see Use Workbench to connect to a Linux instance over SSH.

    2. Run the following command to check disk and partition information:

      sudo fdisk -lu

      截屏2024-11-20 12

      1. Check whether disks are partitioned. The command output in the preceding figure indicates that the instance has three disks: the system disk named /dev/vda, a data disk named /dev/vdb, and another data disk named /dev/vdc. In this example, the data disks are used. In the command output:

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

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

      2. Determine the partitions that need to be extended. In this example, the /dev/vdb data disk is used. In the command output:

        The Size field specifies the disk or partition size. The size of the /dev/vdb1 partition is smaller than the size of the /dev/vdb disk. The /dev/vdb1 partition must be extended.

        Note

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

      3. Determine the partition style of the disk. The Disklabel type field specifies the partition style of the disk. Valid values: dos and gpt. dos indicates the Master Boot Record (MBR) partition style and gpt the GPT partition style. In this example, the GPT-partitioned data disk /dev/vdb is used. The name of the data disk is /dev/vdb. The partition on the data disk is an GPT partition, and the partition name is /dev/vdb1.

        Note
        • The values vary based on the operating system. If the Disk label type field is not displayed, check the System field to determine the partition style. If the value of System is Linux, the MBR partition style is used. If the value is GPT, the GPT partition style is used.

        • If you use an earlier version of fdisk, the GPT partition style may not be displayed. To check the partition style, run the gdisk -l /dev/vdb command.

    3. Run the following command to obtain the file system information of the partition or disk that you want to extend:

      sudo file -s <Raw device name>/<Partition name>

      截屏2024-12-02 10

      The preceding command output indicates that:

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

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

      The unpartitioned /dev/vdd raw device does not have a file system.

      Note

      You can also run the sudo blkid command to obtain the file system information of the partition or disk that you want to extend.

    Method 2: Use the ECS console

    1. Go to the details page of the ECS instance, click the Block Storage tab, and then find the disk whose partitions and file systems must be extended.

    2. Move the pointer over the content of the In-system Information column corresponding to the disk to view the device name, partition style (partition table format), partition name, file system type, and mount point of the disk.截屏2025-01-22 09

      Note

      If the In-system Information column does not appear or no information is displayed in the In-system Information column, you cannot use the Cloud Assistant query feature. In this case, select Method 1: Use the CLI.

  2. Determine the steps that you must perform to extend the partitions and file systems on the disk.

    Note

    For information about the examples on how to extend partitions and file systems, see the Examples section of this topic.

Step 2: Extend partitions

  1. If the disk is not partitioned but has file systems, skip this step to extend partitions and perform Step 3: Extend file systems.

  2. Run commands to extend a partition.

    In this example, the /dev/vdb data disk attached to the Linux ECS instance is resized to 60 GiB in the ECS console, and the /dev/vdb1 partition on the disk is extended from 40 GiB to 60 GiB.

    Run commands to extend a specific partition based on the operating system of the instance and partition style of the disk.

    Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, or 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 the partitions and file systems on a disk that uses the GPT partition style and is attached to a CentOS 6 instance, 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 style

      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 style (gDisk must be installed)

      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 or 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 How do I change Debian 9 or Debian 10 repository addresses?

    • MBR partition style

      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 style (gDisk must be installed)

      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

    Take note of the following items:

    • If you use the growpart utility and errors are reported, see the FAQ section of this topic for troubleshooting.

    • Separate /dev/vdb and 1 with a space in the command. 1 is the partition number. Replace /dev/vdb and 1 with actual values.

    • If you want to extend a partition on the system disk, replace /dev/vdb in the command with /dev/vda.

    • Set the LC_ALL environment variable to en_US.UTF-8 to ensure compatibility with Chinese character sets.

    • If a single disk has successive partitions, you can extend only the last partition. For example, the /dev/vdb data disk has three partitions named /dev/vdb1, /dev/vdb2, and /dev/vdb3. In this case, you can extend only the last partition (/dev/vdb3). To extend the partition, run the growpart /dev/vdb 3 command.

    • If the disk is a Nonvolatile Memory Express (NVMe) disk whose device name is /dev/nvme0n1 and you want to extend the /dev/nvme0n1p1 partition, run the growpart /dev/nvme0n1 1 command instead of the growpart /dev/nvme0n1p1 1 command.

    • If you want to extend a logical partition (whose partition number is greater than or equal to 5 in most cases) of an extended MBR partition, you must extend the extended MBR partition. For example, the following partitions exist: /dev/vdb1 (primary), /dev/vdb2 (extended), and /dev/vdb5 (logical). You must run the growpart /dev/vdb 2 command to extend the /dev/vdb2 partition and then run the growpart /dev/vdb 5 command to extend the /dev/vdb5 partition.

    If CHANGED is displayed as shown in the following figure, the partition is extended.

    image.png

  3. Run the following command to check whether the new partition size takes effect:

    sudo fdisk -lu

    截屏2024-11-20 14

    In the command output shown in the preceding figure, the size of the /dev/vdb data disk is the same as the size of the /dev/vdb1 partition, which indicates that the partition is extended.

    Note

    If the instance runs an earlier version of operating system such as CentOS 6, run the reboot command to restart the instance for the new partition size to take effect.

    In most cases, you do not need to restart instances after you extend disk partitions on the instances. If you extend a partition on the system disk of a CentOS 6 instance or the operating system is of an earlier version and does not recognize the new partition size, restart the instance for the new partition size to take effect. To ensure service continuity, we recommend that you restart instances during off-peak hours.

Step 3: Extend file systems

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 in the ECS console. For more information, see Extend an LV.

    Check whether LVM LVs are used

    Log on to the instance and run the following command:

    sudo lsblk

    The following command output is returned:

    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 LVM LVs are used, partitions whose TYPE value is lvm are displayed in the command output. The preceding command output indicates that the /dev/vdb1 partition is used as an LVM LV. In this case, you must extend the physical volume and the LV before you extend the relevant 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, eXtensible File System (XFS), and new technology file system (NTFS), 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 Multi-attach for cloud disks.

  1. Check whether file systems on a disk must be extended. For more information, see the Determine the steps that you must perform to extend the partitions and file systems on the disk step.

  2. Run the following command to obtain the mount directory of the file system that you want to extend:

    df -Th

    Type specifies the file system type. Mounted on specifies the mount directory of the partition. In the command output shown in the following figure, the file system in the /dev/vdb1 partition is an Ext4 file system, and the partition is mounted to /mnt.

    image.png

    If the Filesystem value does not contain a digit as a suffix, the disk is a raw device. Example: /dev/vdc.

  3. Extend the file system.

    Commands that are used to extend file systems vary based on the file system type. Run one of the following commands to extend a file system based on the file system type that you obtained in Step 1.

    Note

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

    Ext file system, such as Ext2, Ext3, or Ext4

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

      sudo resize2fs /dev/vdb1
      Note

      To extend the file system of the partition on the system disk, replace /dev/vdb1 in the command with /dev/vda1.

    • 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

    For example, to extend the XFS file system that is mounted to the /mnt directory, run one of the following commands based on the instance operating system:

    Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, or CentOS 6 or later

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

    Debian 8 or later or Ubuntu 14 or later

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

    Btrfs file system

    For example, 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 file system is extended:

    df -Th

    If the file system size displayed in the command output is the same as the file system size displayed in the ECS console, the file system is extended.

    The file system size (59 GiB) of the /dev/vdb1 partition shown in the following figure is close to the file system size (60 GiB) displayed in the ECS console, which indicates that the file system is extended. A small size difference exists because the file system information uses storage space. image.png

    After you extend file systems, check the file system sizes.

    • If the file system sizes are increased to the specified values and business applications on the instance run as expected, the file systems are extended.

    • 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 by using a snapshot.

Examples

This section provides sample commands that you can use to extend partitions and file systems. In the examples, MBR partition, GPT partitions, and a raw disk are used. The commands are only for reference. The actual commands may vary based on your environment.

Example 1: Extend an MBR partition and the Ext4 file system of the partition

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

  • Partition: /dev/vda1

  • File system type: Ext4

  • Operating system: Alibaba Cloud Linux 3

Run the following commands to extend the /dev/vda1 partition and the Ext4 file system of the 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/vda 1
sudo resize2fs /dev/vda1

Example 2: Extend a GPT partition and the XFS file system of the partition

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

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

  • File system type: XFS

  • Directory to which /dev/vdb2 is mounted: /mnt

  • Operating system: Debian 12

Run the following commands to extend the /dev/vdb2 partition and the XFS file system of the partition:

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 the file system of a raw data disk

  • Device name: /dev/vdc (unpartitioned raw data disk)

  • File system type: Ext4

  • Operating system: CentOS 7

Run the following command to extend the Ext4 file system of the /dev/vdc raw disk:

sudo resize2fs /dev/vdc

FAQ

FAQ about the growpart utility

  • Question 1: Why does the unexpected output in sfdisk --version [sfdisk, from util-linux 2.23.2] error message appear when I run a growpart command to extend a partition?

    Cause: The Chinese operating system of the instance uses a character encoding type that is not en_US.UTF-8.

    Solution:

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

      • Run the following command to change the character encoding type:

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

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

    Important

    If the partition is extended after you change the character encoding type, we recommend that you switch back to the original character encoding type.

  • Question 2: Why does the unexpected output in sfdisk --version [sfdisk (util-linux-ng 2.17.2)] error message appear when I run a growpart command to extend a partition?

    Cause: The fdisk version is incompatible with the growpart version.

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

  • Question 3: Why does the FAILED: unable to determine partition type error message appear when I run a growpart command to extend a partition?

    Cause: The disk is an unpartitioned raw device. You do not need to extend partitions, but you must extend the file systems of the disk.

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

  • Question 4: Why does the WARNING: MBR/dos partitioned disk is larger than 2TB. Additional space will go unused. error message appear when I run a growpart command to extend a partition?

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

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

  • Question 5: Why does the mkdir: cannot create directory ... No space left on device error message appear when I run a growpart command to extend a partition?

    Cause: The disk space is insufficient and the growpart command cannot create a temporary directory.

    Solution: Delete files that you no longer use and try again. For more information, see Resolve the issue of insufficient disk space on a Linux instance.

  • Question 6: Why does the Error: Cannot retrieve repository metadata error message appear when I install the growpart utility on CentOS 6?

    Cause: CentOS 6 reached EOL. You cannot install CentOS 6 packages by using the default repositories.

    Solution:

  • Question 7: Why does a partition of a disk whose device name starts with /dev/mapper fail to be extended?

    Cause: In most cases, LVM is used to manage disk partitions on disks whose device names start with /dev/mapper.

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

  • Question 8: Why does the NOCHANGE: partition 1 could only be grown by 2015 [fudge=2048] error message appear when I run a growpart command to extend a partition?

    Cause: No disk space is available when you extend the partition. In most cases, this error message appears because you did not restart the instance in the ECS console or by calling an API operation to make the new disk size take effect after you resize the disk offline in the ECS console.

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

FAQ about the resize2fs tool

  • Question 1: Why does the Couldn't find valid filesystem superblock. or open: Is a directory while opening /mnt error message appear when I run a resize2fs command to extend a file system?

    Cause: When you run a resize2fs command to extend the file system of a partition, you must specify the partition name instead of the device name of the disk or the mount directory of the partition.

    Solution: Specify correct partition names when you extend file systems.

  • Question 2: Why does the The filesystem is already ... blocks long. Nothing to do! error message appear when I run a resize2fs command to extend a file system?

    Cause: No disk space is available to extend the file system. This may be caused by an ineffective partition extend operation.

    Solution:

    • Check whether a growpart command is run to extend the partition. If not, run a growpart command to extend the partition.

    • If the partition is extended by running the growpart command, CHANGED is displayed in the command output, and the preceding error message is still returned when you run a resize2fs command, the operating system of the instance may be of an earlier version that does not allow system partition tables to be updated online. Run the reboot command to restart the instance and then run a resize2fs command.

  • Question 3: Why does the resize2fs: Permission denied to resize filesystem error message appear when I run a resize2fs command to extend a file system?

    Cause: File system inconsistency may exist.

    Solution:

    • Run the dmesg -T | grep fs command. If an error message similar to There are errors in the filesystem is displayed in the command output, file system inconsistency exists.

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

    • On the premise that business is not affected, run the umount command to unmount the mounted partition or the entire disk based on the actual scenario.

      Note

      If you cannot unmount the system disk by using the umount command, detach the system disk and then attach the disk to a different instance. For more information, see Detach or attach a system disk.

    • Run the e2fsck command to resolve the issue. For information about how to use the e2fsck command, see the relevant documentation.

FAQ about Cloud Assistant check

Why does the In-system Status Check column display that the check failed?

Your operating system does not support the Cloud Assistant check feature for viewing disk information. Only the following x86 64-bit operating systems support the feature:

  • 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

    To support the feature in Debian 8, 9, 10, or 11, run the sudo apt-get install parted command in the operating system to install the parted utility.

  • 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