You can resize a system disk or a data disk to extend its capacity. If your Linux ECS instance does not support online resizing of disks, you can resize the disks on the instance offline. You must restart the instance after you resize a disk offline for the change to take effect. This will cause your business to be interrupted for a short period of time. We recommend that you resize disks offline at off-peak hours.

Prerequisites

The disk to be resized offline and the instance to which the disk is attached meet the following requirements.
Resource Requirement
Instance
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, you cannot resize the subscription disks on the instance for the remainder of the current billing cycle.
Notice A disk in the master boot record (MBR) partition format cannot be resized to 2 TiB or greater in size. To resize an MBR disk to larger than 2 TiB, we recommend that you create a new disk larger than 2 TiB, partition and format the new disk 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 use the GPT format to partition and format disks, see Partition and format a data disk larger than 2 TiB.

Background information

The following table lists configurations of the instance and disks that are 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 ext4 file system, and is resized from 40 GiB to 60 GiB.
Data disk
  • /dev/vdb: uses the MBR partition format and ext4 file system, and is resized from 40 GiB to 60 GiB.
  • /dev/vdc: uses the GPT partition format and xfs file system, and is resized from 40 GiB to 60 GiB.

Step 1: Create a snapshot

Create a snapshot for the disk to back up the disk data before you resize 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 Disks in the left-side navigation pane.
  6. Find the disk that you want to resize, and click Create Snapshot in the Actions column.
  7. In the dialog box that appears, enter a snapshot name, specify tags, and then click Create.
  8. Click Snapshots in the left-side navigation pane to view the snapshot.
    When 100% appears in the Progress column corresponding to the snapshot, the snapshot is created. You can continue to perform subsequent operations.

Step 2: Resize the disk, and restart or start the instance in the 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 then click Resize Disk in the lower part of the page. Disks that are attached to the same instance cannot be batch resized.

  3. On the Resize Disks page, set the Size after Resize parameter.
    The specified Size after Resize value cannot be less than the current capacity.
  4. Verify the price. Read and select ECS Service Terms, and then click Confirm.
  5. Read the notes, and click I have read the notes. Resize to complete the payment.
  6. Restart or start the instance in the ECS console.
    Note
    • If your instance is in the Running (Running) state, you must restart the instance in the console. If your instance is in the Stopped (Stopped) state, you must start the instance in the console.
    • The disk resizing operation takes effect only after you restart or start the instance by using the console or by calling the RebootInstance operation. If the ECS instance is restarted from within the instance itself, the disk capacity does not change.

    The following procedure demonstrates how to restart an instance.

    1. In the left-side navigation pane, choose Instances & Images > Instances.
    2. Find the instance to be restarted, and choose More > Instance Status > Restart in the Actions column.
    3. In the Restart Instance dialog box, click OK.

Step 3: View the disk partitions

Log on to the ECS instance to view the partition types (MBR and GPT) and file system types (such as ext4 and xfs) of the system disk and data disks. Subsequent resizing operations vary based on the types of the partitions and file systems.

  1. Connect to the ECS instance. For more information,see Connect to a Linux instance by using VNC.
  2. Run the following command view the disks attached to the instance:
    fdisk -lu
    The following figure shows a partition of the system disk (/dev/vda1) and two partitions of data disks (/dev/vdb1 and /dev/vdc1).View the partitions of the disks
    No. Partition Description
    /dev/vda1 The partition of the system disk. The System value of Linux indicates that the partition is in the MBR format.
    /dev/vdb1 A partition of a data disk. The System value of Linux indicates that the partition is in the MBR format.
    /dev/vdc1 A partition of a data disk. The System value of GPT indicates that the partition is in the GPT format.
  3. Run the following command to check the file system types of the existing partitions:
    df -Th

    An output similar to the following one is displayed:

    View the file systems

Step 4: Resize partitions

When you view the disk partitions, you can find that the partitions and file systems within the ECS instance have not been resized. This step describes how to resize the partitions of the resized disk within the ECS instance.

  1. Install the gdisk tool on the ECS instance.
    You must perform this step if the partitions are in the GPT format. Skip this step if the partitions are in the MBR format.
    yum install gdisk -y
  2. Install the growpart tool.
    • Run the following command if the instance runs CentOS 7 or later:
      yum install -y cloud-utils-growpart
    • Run the following command if the instance runs Debian 9 or later or Ubuntu 14 or later:
      apt install -y cloud-guest-utils
  3. Run the following command to resize partitions:
    growpart /dev/vda 1
    In this example, the partition of the system disk is resized. Use a space to separate /dev/vda and 1. To resize other partitions, modify the command accordingly. An output similar to the following one is displayed:growpart
    Note When you run the growpart /dev/vda 1 command, the unexpected output in sfdisk --version [sfdisk, from util-linux 2.23.2] error may be prompted. For information about how to troubleshoot this problem, see the FAQ section in this topic.

Step 5: Resize file systems

This step describes how to resize the file system of a partition within an ECS instance.

  1. Resize the file systems within the ECS 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 a data disk, run the following command:

      resize2fs /dev/vdb1          
      Note /dev/vda1 and /dev/vdb1 are partition names. Change the commands based on your partition names.
    • To resize xfs file systems, run the following command:
      xfs_growfs /media/vdc
      Note /media/vdc is the mount point of the /dev/vdc1 partition. Change the command based on the mount point of your partition.
  2. Run the following command to check the resizing results:
    df -Th

    An output similar to the following one is displayed:

    Check the resizing results
    After the disk is resized, check whether the new capacity of the disk is as expected.
    • If the file systems are resized and the business programs in the instance can run properly, the resizing operation is complete.
    • If the file systems fail to be resized, use the snapshot that you created in Step 1 to roll back the disk.

FAQ

  • Problem description: When the growpart /dev/vda 1 command is run, the unexpected output in sfdisk --version [sfdisk, from util-linux 2.23.2] error is prompted.
    Solution:
    1. Run the locale command to view the character encoding type of the ECS 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 problem persists, run the following command to switch the character encoding type:
        export LC_ALL=en_US.UTF-8
      3. If the problem persists, run the following command to switch the character encoding type:
        localectl set-locale LANG=en_US.UTF-8
      4. If you are using a CentOS 8 image and the preceding solution cannot solve the problem, run the following command to switch the character encoding type:
        export LANGUAGE=en_US.UTF-8
    2. If the problem persists, run the reboot command to restart the ECS instance.
    Notice

    After you resize the partition by switching the character encoding type, we recommend that you switch back to the original character encoding type.

  • Problem description: When the growpart /dev/vda 1 command is run, the -bash: growpart: command not found error is prompted.
    Solution:
    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 can extend partitions of a disk on the instance. 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.
      • Run the following command if the instance runs CentOS 7 or later:
        yum install -y cloud-utils-growpart
      • Run the following command if the instance runs Debian 9 or later or Ubuntu 14 or later:
        apt install -y cloud-guest-utils

Other scenarios for disk resizing