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.
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.
ImportantTo extend partitions and file systems on a disk that uses the GUID Partition Table (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 thegrowpart
command described in this topic. Otherwise, the partition table may be corrupted. Check whether the disk uses the GPT partition style. For more information, see the Step 1: Obtain disk information section of this topic.For information about how to extend the partitions and file systems on disks attached to an ECS instance that runs a different operating system, see Extend partitions and file systems on a data disk of a Linux instance offline.
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%.
ImportantYou 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.
NoteIf 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.
NoteIn 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)
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.
Click the Use Cloud Assistant tab on the Expand Partitions and File Systems page.
On the Block Storage tab of the instance details page, enable the Cloud Assistant check feature.
NoteThis 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.
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.
NoteOnly 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.
Use Cloud Assistant to extend partitions and file systems.
Click Run Preceding Command in the lower part of the Command Content section to extend the partitions and file systems.
NoteIf 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.
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.
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
Obtain disk information.
Method 1: Use the CLI
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.
Run the following command to check disk and partition information:
sudo fdisk -lu
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).
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.NoteYou can also run the
lsblk
command to check which partition needs to be extended.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 andgpt
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.NoteThe values vary based on the operating system. If the
Disk label type
field is not displayed, check theSystem
field to determine the partition style. If the value ofSystem
isLinux
, the MBR partition style is used. If the value isGPT
, 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.
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>
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.
NoteYou 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
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.
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.
NoteIf 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.
Determine the steps that you must perform to extend the partitions and file systems on the disk.
If MBR partitions exist on the disk, the new size of the disk exceeds 2 TiB, and you want to extend existing partitions to the added disk space, you can change the partition style of the disk to GPT and perform Step 2: Extend partitions and Step 3: Extend file systems.
If MBR or GPT partitions exist on the disk, the new size of the disk does not exceed 2 TiB, and you want to extend existing partitions to the added disk space, perform Step 2: Extend partitions and Step 3: Extend file systems.
NoteYou can also create partitions in the added disk space instead of extending existing partitions. For more information, see the Method 2: Create and format MBR partitions and Method 4: Create and format GPT partitions sections of the "Extend partitions and file systems on a data disk of a Linux instance offline" topic.
If the disk is not partitioned but has file systems, skip the steps to extend partitions and perform Step 3: Extend file systems.
If the disk is not partitioned and does not have file systems, you do not need to perform the operations described in this topic.
NoteFor information about the examples on how to extend partitions and file systems, see the Examples section of this topic.
Step 2: Extend partitions
If the disk is not partitioned but has file systems, skip this step to extend partitions and perform Step 3: Extend file systems.
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
ImportantCentOS 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
ImportantDebian 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
ImportantTake 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
and1
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 thegrowpart /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 thegrowpart /dev/nvme0n1 1
command instead of thegrowpart /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 thegrowpart /dev/vdb 2
command to extend the /dev/vdb2 partition and then run thegrowpart /dev/vdb 5
command to extend the /dev/vdb5 partition.
If
CHANGED
is displayed as shown in the following figure, the partition is extended.Run the following command to check whether the new partition size takes effect:
sudo fdisk -lu
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.
NoteIf 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
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.
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.
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.
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.If the Filesystem value does not contain a digit as a suffix, the disk is a raw device. Example:
/dev/vdc
.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.
NoteIf 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
NoteTo 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
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.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