After you attach a new data disk to an Elastic Compute Service (ECS) instance, you
must create and mount one or more file systems on the disk. This topic describes how
to partition and format a new data disk on a Linux instance.
Prerequisites
A data disk that is created together with an instance is automatically attached to
the instance. An independent data disk is created and attached to an instance. For
more information about how to attach data disks to ECS instances, see
Attach a data disk.
Note The attach operation refers to attaching disks to ECS instances in the ECS console,
instead of mounting file systems by running the mount command within the operating systems of ECS instances.
Background information
By default, the device names of data disks are assigned by the system based on the
following naming conventions:
- I/O optimized instances:
- The device names of data disks that are attached by using the Non-Volatile Memory
Express (NVMe) protocol use the /dev/nvmeXn1 format. Examples: /dev/nvme1n1, /dev/nvme2n1, and /dev/nvme3n1. For more information about disks that support NVMe, see Overview of disks that support NVMe.
- The device names of data disks that are attached not by using the NVMe protocol use
the /dev/vd[b-z] format. Examples: /dev/vdb, /dev/vdc, and /dev/vdd.
- The device names of data disks that are attached to non-I/O optimized instances use
the /dev/xvd[b-z] format. Examples: /dev/xvdb, /dev/xvdc, and /dev/xvdd.
Data disks support the GUID Partition Table (GPT) and Master Boot Record (MBR) partition
formats.
- GPT: can recognize partitions larger than 2 TiB in size and allows an unlimited number
of partitions to be created on each disk.
- MBR: can recognize partitions up to 2 TiB in size and allows up to four partitions
to be created on each disk.
Precautions
When you partition and format a data disk, take note of the following items:
- Disk partitioning and formatting are high-risk operations. Proceed with caution when
you partition and format disks. This topic applies only to new data disks.
If a data disk that you want to format contains data, you must create snapshots for
the disk before you format it. This can prevent data loss. For more information, see
Create a snapshot of a disk.
- In ECS, only data disks can be partitioned, whereas system disks cannot.
If you use a third-party tool to forcefully partition a system disk, unforeseen risks
such as system failures and data loss may occur. You can only extend or create partitions
on system disks that have been extended. For more information, see Resize disks online for Linux instances.
Procedure
The following table describes the resources used in the examples of this topic.
Resource |
Description |
Image used by the instance |
Alibaba Cloud Linux 3.2104 64-bit public image |
Data disk |
- Device name of the data disk: /dev/vdb
- Capacity: 40 GiB
|
Step 1: Connect to an ECS instance and view the data disk
Connect to an ECS instance and check whether the data disk is attached to the ECS
instance.
- Connect to the ECS instance.
- Run the following command to view the information of the data disk attached to the
ECS instance:
fdisk -l
A command output similar to the following one is returned.

If no /dev/vd* device name is displayed, check whether the data disk is attached to the instance.
/dev/vd* indicates the new data disk. In this example, /dev/vdb is used. For information about how to attach a data disk in the ECS console, see
Attach a data disk.
- Create a partition for the data disk.
Step 2: Create a GPT partition for the data disk
Perform the following steps to create a GPT partition that is larger than 2 TiB in
size for the data disk.
- If Parted and e2fsprogs are not installed, run the following commands to install them.
- Run the following command to install Parted:
yum install -y parted
- Run the following command to install e2fsprogs:
yum install -y e2fsprogs
Note The yum command in this step is applicable to Linux distributions such as CentOS.
For other Linux distributions, modify the command based on your package management
software. For example, run the apt-get install <Package name>
command for Debian or Ubuntu.
- Use Parted to partition the data disk.
- Run the following command to start partitioning the data disk:
- Run the following command to set the partition format to GPT:
- Run the following command to create a primary partition and specify the start and
end sectors for the partition:
- Run the following command to check whether the partitions are aligned:
align-check optimal 1
A command output similar to the following one is returned:
1 aligned
Note If the partition is not aligned,
1 not aligned
is returned. For more information about how to troubleshoot this issue, see
FAQ.
- Run the following command to view the partition table:
- Run the following command to exit Parted:
A command output similar to the following one is returned.

- Run the following command to re-read the partition table:
- Run the following command to view the new partition:
fdisk -lu /dev/vdb
A command output similar to the following one is returned. If the new partition is
created, the information of gpt is displayed.

Step 2: Create an MBR partition for the data disk
Perform the following steps to create an MBR partition that is up to 2 TiB in size
for the data disk.
Note If your data disk is larger than 2 TiB in size or if you may need to extend your data
disk to larger than 2 TiB in size, we recommend that you use the GPT partition format.
For more information, see
Step 2: Create a GPT partition for the data disk.
- Create an MBR partition.
- Run the following command to partition the data disk:
- Enter p to view the partition information of the data disk.
In this example, the data disk is not partitioned.
- Enter n to create a partition.
- Enter p to set the partition as a primary partition.
Note When you create a single partition for a data disk, the partition must be the primary
partition. If you want to create four or more partitions, enter e (extended) at least once to create at least one extended partition.
- Enter the partition number and press the Enter key.
In this example, only one partition is created. Press the Enter key to use the default
value 1.
- Enter the number of the first available sector and press the Enter key.
In this example, press the Enter key to use the default value 2048.
- Enter the number of the last sector and press the Enter key.
In this example, only one partition is created. Press the Enter key to use the default
value.
- Enter p to view the partition information of the data disk.
- Enter w to start partitioning. Then, exit after the disk is partitioned.
A command output similar to the following one is returned.

- Run the following command to view the new partition:
fdisk -lu /dev/vdb
A command output similar to the following one is returned. If the new partition is
created, the information of /dev/vdb1 is displayed.

Step 3: Create a file system for the partition
Create a file system for the new partition. The following commands are applicable
to ext4 and XFS file systems. You can run one of the following commands to create
the corresponding file system.
- Run the following command to create an ext4 file system:
mkfs -t ext4 /dev/vdb1
- Run the following command to create an XFS file system:
mkfs -t xfs /dev/vdb1
A command output similar to the following one is returned. In this example, an ext4
file system is created.

Step 4: Configure the /etc/fstab file and mount the partition
Write the information of the new partition to /etc/fstab to enable this partition to be automatically mounted on instance startup.
Notice We recommend that you use a universally unique identifier (UUID) to reference the
new partition in /etc/fstab. The device names of other disks may change due to operations such as releasing a
disk. If you use the device name of the data disk in /etc/fstab, your stored data may be affected if the device name changes.
- Run the following command to back up etc/fstab:
cp /etc/fstab /etc/fstab.bak
- Write the information of the new partition to /etc/fstab.
- Run the following command to check the information of the new partition in /etc/fstab:
cat /etc/fstab
A command output similar to the following one is returned.

- Run the following command to mount the file system configured in the /etc/fstab file:
- Run the following command to check the mount result:
df -h
A command output similar to the following one is returned. If the file system is mounted,
the information of the new file system is displayed.

FAQ
Issue: When GPT partitions are created, the partitions are not aligned.
Solution:
- We recommend that you run the following commands:
cat /sys/block/vdb/queue/optimal_io_size
cat /sys/block/vdb/queue/minimum_io_size
cat /sys/block/vdb/alignment_offset
cat /sys/block/vdb/queue/physical_block_size
- Calculate the start sector number of the optimal partition format by using the following
formula:
(<optimal_io_size>+<alignment_offset>) /<physical_block_size>
.
For example, if the start sector number is 1024, you can run the mkpart primary 1024s 100%
command to create another primary partition.