You can resize system and data disks to extend their capacities. This topic describes how to resize a disk for an Elastic Compute Service (ECS) Linux instance when the instance is running.

Prerequisites

The requirements described in the following table are met before you can resize a disk online for a Linux instance.
Resource Requirement
Instance
Note If your instance does not meet the preceding requirements on resizing disks online, you can resize its disks offline. For more information, see Resize disks offline for Linux instances.
Disk
  • The disk is in the In Use (In Use) state.
  • The disk is an enhanced SSD (ESSD), a standard SSD, or an ultra disk.
  • After you renew a subscription instance and downgrade its configurations, the subscription disks of the instance cannot be resized for the remainder of the current billing cycle.
  • When you resize a disk of a specific category, the specified new disk capacity cannot exceed the maximum single-disk capacity allowed for the disk category. For more information, see the "Elastic Block Storage (EBS) limits" section in Limits.
Notice A disk in the master boot record (MBR) partition format cannot be resized to 2 TiB or larger. To resize an MBR disk to larger than 2 TiB, we recommend that you create a disk with the desired capacity, partition and format the new disk to the GUID Partition Table (GPT) format, and then copy data from the original MBR disk to the new GPT disk. For more information about how to partition and format disks to GPT, see Partition and format a data disk larger than 2 TiB in size.

Background information

The following table describes the resources used in the examples of this topic.
Resource Description
Image used by the instance Alibaba Cloud Linux 2.1903 LTS 64-bit public image
System disk /dev/vda: uses the MBR partition format and the ext4 file system, and is resized from 40 GiB to 60 GiB.
Data disks
  • /dev/vdb: uses the MBR partition format and the ext4 file system, and is resized from 40 GiB to 60 GiB.
  • /dev/vdc: uses the GPT partition format and the XFS file system, and is resized from 40 GiB to 60 GiB.

Step 1: Create a snapshot

Before you resize a disk online, you must create a snapshot for the disk to back up the data stored on the disk.

  1. Log on to the ECS console.
  2. In the left-side navigation pane, choose Instances & Images > Instances.
  3. In the top navigation bar, select a region.
  4. Find the instance whose disk you want to resize and click the instance ID.
  5. On the Instance Details page, click the Cloud Disk tab.
  6. Find the disk that you want to resize and click Create Snapshot in the Actions column.
  7. In the Create Disk Snapshot dialog box, enter a snapshot name, configure tags, and then click OK.
  8. Click the Snapshot tab to view the snapshot.
    After the snapshot is created, 100% appears in the Progress column that corresponds to the snapshot. Then, you can proceed to perform subsequent operations.

Step 2: Resize the disk in the ECS console

  1. On the Instance Details page, click the Cloud Disk tab.
  2. Find the disk that you want to resize and choose More > Resize Disk in the Actions column.
    To batch resize disks, log on to the ECS console by using your Alibaba Cloud account and choose Storage & Snapshots > Disks in the left-side navigation pane. On the Disks page, select the disks that you want to resize and click Resize Disk in the lower part of the page. Disks that are attached to the same instance cannot be resized together.
    Note Alibaba Cloud accounts are permitted to batch resize disks but RAM users are not. To batch resize disks, log on to the ECS console by using your Alibaba Cloud account.
  3. On the Resize Disks page, select Online Resizing and set the Size after Resize parameter.
    The specified Size after Resize value must be greater than the current capacity.
  4. Verify the price. Read and select ECS Service Terms, and then click Confirm.
  5. Read the notes, click I have read the notes. Resize, and then complete the payment.
Notice
  • After you resize the disk in the ECS console, you must resize the partitions and file systems of the disk within the instance before you can use the new capacity of the disk.
  • If you use Logical Volume Manager (LVM) to manage your disk partitions, you must use LVM to resize the partitions and file systems after you resize your disk in the ECS console. For more information, see Resize an LV by using LVM.

Step 3: View the disk partitions

You can log on to the instance to view the partition types (such as MBR and GPT) and file system types (such as ext4 and XFS) of the system disk and data disks. Subsequent resize operations vary based on the partition and file system types of the disks.

  1. Log on to the instance. For more information, see Connect to a Linux instance by using password authentication.
  2. Run the following command to view the disks attached to the instance:
    fdisk -lu
    The following command output shows the /dev/vda1 partition of the system disk and the /dev/vdb1 and /dev/vdc1 partitions of data disks. View the partitions of the disks
    No. Partition Description
    /dev/vda1 A partition of the system disk. A value of Linux for System indicates that the partition is in the MBR format.
    /dev/vdb1 A partition of a data disk. A value of Linux for System indicates that the partition is in the MBR format.
    /dev/vdc1 A partition of a data disk. A value of GPT for System indicates that the partition is in the GPT format.
    Note If the capacity of the system disk (/dev/vda) in the command output is still 40 GiB (Disk /dev/vda: 42.9 GB), the disk was not resized. We recommend that you restart the instance in the ECS console.
  3. Run the following command to check the file system types of existing partitions:
    df -Th

    A command output similar to the following one is displayed. In the command output, the Mounted on column lists the mount points that correspond to the file systems.

    View the file systems

Step 4: Resize partitions

When you view the partitions of a resized disk, you may find that the partitions and file systems within the instance were not resized. This step describes how to resize the partitions of the resized disk within the instance.

  1. Install the gdisk tool on the instance.
    If the partitions are in the GPT format, you must perform this step. If the partitions are in the MBR format, skip this step.
    yum install gdisk -y
  2. Install the growpart tool.
    • If the instance runs an Alibaba Cloud Linux 2 or 3 operating system or a CentOS 7 or later operating system, run the following command:
      yum install -y cloud-utils-growpart
      Note CentOS 8 has reached its end of life (EOL). If your instance runs a CentOS 8 operating system, change the CentOS 8 repository address. For more information, see Change CentOS 8 repository addresses.
    • If the instance runs a Debian 8 or later operating system or an Ubuntu 14 or later operating system, run the following commands.

      Run the following command to update the software repository:

      apt-get update

      Run the following command to install cloud-guest-utils:

      apt-get install -y cloud-guest-utils
  3. Run the following command to resize partitions:
    growpart /dev/vda 1
    In this example, the first partition of the system disk is resized. /dev/vda is the system disk and 1 is the partition number. Use a space to separate /dev/vda from 1. growpartModify the command accordingly to resize other partitions.
    • Run the following command to resize the /dev/vdb data disk:
      growpart /dev/vdb 1
    • Run the following command to resize the /dev/vdc data disk:
      growpart /dev/vdc 1
    Note
    • If a single disk has successive partitions, you need to only resize the last partition to resize the disk. For example, the /dev/vdb data disk has three partitions named /dev/vdb1, /dev/vdb2, and /dev/vdb3, you can run only the growpart /dev/vdb 3 command to resize the /dev/vdb data disk.
    • When you run the growpart /dev/vda 1 command, the unexpected output in sfdisk --version [sfdisk, from util-linux 2.23.2] error message may appear. For information about how to troubleshoot this issue, see the "FAQ" section of this topic.

Step 5: Resize file systems

This step describes how to resize the file systems of partitions within the instance.

  1. Resize the file systems within the instance based on the file system types that you obtained.
    • To resize ext* (such as ext4) file systems, run the following commands.
      To resize the file system of the /dev/vda1 partition of the system disk, run the following command:
      resize2fs /dev/vda1    
      To resize the file system of the /dev/vdb1 partition of the data disk, run the following command:
      resize2fs /dev/vdb1          
      Note /dev/vda1 and /dev/vdb1 are partition names. Replace them with the names of your partitions.
    • To resize the xfs file system of the /dev/vdc1 partition of the data disk, run the following command:
      xfs_growfs /media/vdc
      Note /media/vdc is the mount point of the /dev/vdc1 partition. Replace it with the mount point of your partition.
    • To resize the btrfs file system of a data disk, run the following command:
      btrfs filesystem resize max /mountpoint
      Note /mountpoint is the mount point of the data disk. Replace it with the mount point of your data disk.
  2. Run the following command to check the resize results:
    df -Th

    A command output similar to the following one is displayed.

    Check the resize results
    After you resize the file systems, check whether their actual sizes are consistent with the new specified values.
    • If the file system sizes are increased to the new specified values and the business programs on the instance can run normally, the resize operation is complete.
    • If the file system sizes are not increased to the new specified values, use the snapshot that you created in Step 1 to roll back the disk.

Operating systems (images) that support online resizing of disks

The following Linux public images and custom images derived from these public images support online resizing of disks:
  • Alibaba Cloud Linux: Alibaba Cloud Linux 2 and Alibaba Cloud Linux 3
  • CentOS:
    • CentOS 6: CentOS 6.8 and later
    • CentOS 7: CentOS 7.2 and later
    • CentOS 8 and later
  • Red Hat Enterprise Linux (RHEL):
    • RHEL 6: RHEL 6.9 and later
    • RHEL 7: RHEL 7.4 and later
    • RHEL 8 and later
  • Ubuntu: Ubuntu 16 and later
  • Debian: Debian 8 and later
  • SUSE: SUSE 12 SP2 and later
  • openSUSE: openSUSE 42.3 and later

FAQ

  • Question: When the growpart /dev/vda 1 command is run on the Linux instance, the unexpected output in sfdisk --version [sfdisk, from util-linux 2.23.2] error message appears. What do I do?
    Answer:
    1. 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 it to en_US.UTF-8.
      1. Run the following command to switch the character encoding type:
        LANG=en_US.UTF-8
      2. If the error persists, run the following command to switch the character encoding type:
        export LC_ALL=en_US.UTF-8
      3. If the error still persists, run the following command to switch the character encoding type:
        localectl set-locale LANG=en_US.UTF-8
      4. If the preceding solutions do not resolve the error, run the following command to switch the character encoding type:
        export LANGUAGE=en_US.UTF-8
    2. If the error persists, run the reboot command to restart the instance.
    Notice

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

  • Question: When the growpart /dev/vda 1 command is run on the Linux instance, the -bash: growpart: command not found error message appears. What do I do?
    Answer:
    1. Run the uname -a command to check the version of the Linux kernel. The procedure described in this topic applies to Linux kernel 3.6.0 and later.

      If the version of the Linux kernel is earlier than 3.6.0, you must resize the partitions of disks after you resize the disks. For more information, see Procedure for instances with kernels earlier than 3.6.0 and Resize partitions and file systems of Linux data disks.

    2. Install the growpart tool.
      • If the instance runs a CentOS 7 or later operating system, run the following command:
        yum install -y cloud-utils-growpart
        Note CentOS 8 has reached its end of life (EOL). If your instance runs a CentOS 8 operating system, change the CentOS 8 repository address. For more information, see Change CentOS 8 repository addresses.
      • If the instance runs a Debian 8 or later operating system or an Ubuntu 14 or later operating system, run the following command:
        apt install -y cloud-guest-utils
  • Question: The growpart tool used to resize partitions cannot be installed on an instance that runs CentOS 6.5. Why?
    Answer: The Linux kernel version of CentOS 6 is earlier than 3.6.0. To install the growpart tool on CentOS 6, perform the following steps:
    1. Change the YUM repository address for CentOS 6. For more information, see Change the CentOS 6 source address.
      Note CentOS 6 has reached its EOL. To use YUM to install CentOS software packages, you must change the YUM repository address for CentOS 6.
    2. Install the dracut-modules-growroot tool on the instance that runs CentOS 6 to resize the partitions of disks. For more information, see Procedure for instances with kernels earlier than 3.6.0.

Other scenarios for disk resizing