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.
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 instance is Running.
The Linux instance runs one of the following operating systems: Alibaba Cloud Linux 2 or 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, you must 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. To check whether the disk uses the GPT partition style, see the Step 1: Obtain disk information section of this topic.For other operating systems, see Scale out partitions and file systems on a Linux data disk offline.
The disk must meet the following conditions:
The disk status is In Use.
The system disk usage is less than 100%.
ImportantTo 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.
NoteIf 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.
NoteAlthough 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)
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.
Navigate to the interface for extending partitions and file systems using Cloud Assistant.
On the Block Storage page of the instance details page, you can enable the Cloud Assistant detection feature.
NoteThis 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.
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.
NoteThe 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.
Extend the partitions and file systems using Cloud Assistant.
After entering the command to extend partitions and file systems, click Execute Remote Command.
NoteIf 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.
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.
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
Obtain the disk information.
Method 1: Use the command line
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.
Run the following command to identify the name of the disk to be extended and its partitions.
sudo fdisk -lu
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).
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.NoteYou can also run the
lsblk
command to check which partition needs to be extended.Identify the partition style of the disk.
Disklabel type
indicates the partition style of the disk. A value ofdos
indicates an MBR partition. A value ofgpt
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.NoteThe display varies slightly across operating systems. If the
Disk label type
field is not present, check theSystem
field. ASystem
value ofLinux
indicates an MBR partition. A value ofGPT
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.
Run the following command to obtain the file system information of the disk to be extended.
sudo file -s raw_device_name/partition_name
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.
NoteYou can also run the sudo blkid command to obtain the file system information of the disk to be extended.
Method 2: Use the console
On the Block Storage tab of the instance details page, find the disk that you want to extend.
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.
NoteIf 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.
Determine which extension steps to perform.
If the disk has MBR partitions, its new size exceeds 2 TiB, and you want to extend existing partitions into the added disk space, you must first change the partition style of the disk to GPT. Then, perform Step 2: Extend partitions and Step 3: Extend file systems.
If the disk has MBR or GPT partitions, its new size does not exceed 2 TiB, and you want to extend existing partitions into the added disk space, perform Step 2: Extend partitions and Step 3: Extend file systems.
NoteIf you want to add a new partition instead of extending an existing partition, see Add and format an MBR partition and Option 4: Add and format a GPT partition.
If the disk is not partitioned but has a file system, you do not need to extend the partition. You can proceed directly to Step 3: Extend the file system.
If the disk is not partitioned and has no file system, you do not need to perform the operations in this topic.
NoteFor specific extension examples, see Extension examples.
Step 2: Extend the partition
If your disk is not partitioned but has a file system, proceed directly to Step 3: Extend the file system.
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
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 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
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 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
ImportantNote 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
and1
.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 thegrowpart /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 thegrowpart /dev/nvme0n1 1
command, notgrowpart /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 rungrowpart /dev/vdb 2
and thengrowpart /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.Run the following command to check whether the partition was extended.
sudo fdisk -lu
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.
NoteFor 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
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.
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.
Refer to Determine which extension steps to perform to confirm whether you need to extend the file systems on the disk.
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 ofMounted 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.If the value of Filesystem does not have a number as a suffix (for example,
/dev/vdc
), it is a raw device.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.
NoteIf 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
NoteIf 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
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.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