After you attach a new data disk to a Linux Elastic Compute Service (ECS) instance, you must initialize the data disk before the disk can be recognized and used to store data by the operating system. This topic describes how to initialize a data disk on a Linux ECS instance. The initialization operations include partitioning the data disk and mounting file systems on the data disk.
Prerequisites
An empty data disk is created. For information about how to create an empty data disk, see Create an empty data disk.
The data disk is attached to a Linux ECS instance and is in the In Use state. For information about how to attach a data disk to an ECS instance, see Attach a data disk.
NoteData disks created together with a Linux ECS instance are already attached to the instance.
Method 1: Use Cloud Assistant to automatically initialize a data disk
If a data disk meets the following requirements, you can use Cloud Assistant to automatically initiate the data disk. Otherwise, use Method 2: Log on to an ECS instance and manually initiate a data disk .
Use Cloud Assistant to initiate the data disk.
If the data disk is a new empty disk (a disk that is not partitioned and on which no file systems are mounted), you must create partitions and mount file systems on the disk.
If the data disk is created from a snapshot or is detached from a different ECS instance but no file systems are mounted on the disk, you need to only mount file systems on the disk.
Create partitions and mount file systems on a data disk
On the Instance page in the ECS console, find the ECS instance to which the data disk that you want to initialize is attached. Click the instance ID to go to the Instance Details page and then click the Block Storage tab. Enable the Cloud Assistant Check feature. By default, the feature is enabled.
NoteIf the Cloud Assistant Check feature is unavailable, you cannot use Cloud Assistant to initialize a data disk. In this case, use Method 2: Log on to an ECS instance and manually initiate a data disk.
Find the data disk that you want to initialize, move the pointer over 0/3 Check Passed in the In-system Status Check column, and then click Initialize Data Disk.
NoteIf the In-system Status Check column does not appear or the In-system Status Check column displays that the check fails, you cannot use the Cloud Assistant Check feature. In this case, use Method 2: Log on to an ECS instance and manually initiate a data disk.
Configure partition information.
Specify partition sizes (Size) and mount points.
NoteYou can click Create Partition to create multiple partitions on the data disk based on your business requirements. You can create up to five partitions on a cloud disk.
Size: The size of each partition or the total size of all partitions cannot exceed the size of the data disk.
NoteReserve 1 MiB to 2 MiB of storage space for the partition table and sector alignment of partitions. The partitioning feature reduces the size of the last partition to reserve the required storage space. As a result, the actual partition size may be slightly smaller than the specified partition size. The total size of partitions may also be smaller than the disk size.
File System Type: The data disk supports only Ext4 file systems, and the default partition format is GPT.
Mount Point: The mount point must start with a forward slash (/) and can contain letters and digits. Example: /mnt. Specify an existing directory that does not contain data or create a directory as the mount point. Mount points must be unique.
ImportantIf you specify an existing directory that contains data, the data is overwritten when a file system is mounted on the directory. This may cause data loss and affect your business.
Read the risk warning, select the check box, and then click OK. If Normal is displayed in the Status column corresponding to the data disk on the Check Disk Status (Cloud Assistant) page, the data disk is initialized.
(Optional) Configure the partitions on the data disk to automatically mount on instance startup. For more information, see the (Optional) Step 4: Configure the disk partitions to automatically mount on instance startup section of this topic.
Only mount file systems on a data disk
On the Instance page in the ECS console, find the ECS instance to which the data disk that you want to initialize is attached. Click the instance ID to go to the Instance Details page and then click the Block Storage tab. Enable the Cloud Assistant Check feature. By default, the feature is enabled.
Find the data disk on which you want to mount file systems, move the pointer over 1/3 Check Passed in the In-system Status Check column, and then click Mount File Systems.
In the Partition and Mount Settings section, configure the Mount Point parameter and click Manually Mount to mount file systems.
NoteSpecify an existing directory that does not contain data or create a directory as the mount point. Mount points must be unique.
(Conditionally required) If the data disk is created from a snapshot and is attached to the ECS instance to which the source disk of the snapshot is attached, the UUID of the data disk conflicts with the UUID of the source disk. You must change the UUID of the data disk. For more information, see Change the UUID of a disk.
(Conditionally required) If the data disk is created from a snapshot and is larger than the source disk of the snapshot, you must extend partitions and file systems on the data disk before you can use the data disk.
For information about how to extend partitions and file systems on a cloud disk attached to a Linux ECS instance, see Extend the partitions and file systems of disks on a Linux instance.
For information about how to extend partitions and file systems on a cloud disk attached to a Windows ECS instance, see Extend the partitions and file systems of disks on a Windows instance.
(Optional) Configure the partitions on the data disk to automatically mount on instance startup. For more information, see the (Optional) Step 4: Configure the disk partitions to automatically mount on instance startup section of this topic.
Method 2: Log on to an ECS instance and manually initiate a data disk
In this example, an ECS instance that runs Alibaba Cloud Linux 3 is used. The commands that you can run to initialize a data disk may vary based on the instance operating system.
Step 1: Connect to the Linux ECS instance and view the data disks
Connect to the ECS instance.
For more information, see Use Workbench to connect to a Linux instance over SSH.
Run the following commands to obtain the device name of the data disk that needs to be initialized:
sudo fdisk -lu sudo blkid
The following figure shows the command outputs of the preceding commands. The output of the sudo fdisk -lu command indicates that three disks are attached to the Linux ECS instance. Compare the outputs of the sudo fdisk -lu and sudo blkid commands.
/dev/vda
is the system disk, which is created together with the instance and already initialized./dev/vdb
is a data disk, which does not have partitions but has an Ext4 file system. You do not need to initialize the data disk./dev/vdc
is another data disk, for which no information is returned in the output of the sudo blkid command. You must initialize the data disk.
In this example, the device name of the data disk that needs to be initialized is
/dev/vdc
.Determine the steps that you must perform to initialize the data disk.
If you want to use partitions to store and manage data and the data disk that you want to initialize is larger than 2 TiB in size or needs to be subsequently extended beyond 2 TiB, you can create only GPT partitions on the data disk due to partition format limitations. For more information, see the (Recommended) Create a GPT partition and Step 3: Create and mount a file system sections of this topic.
If you want to use partitions to store and manage data and the data disk that you want to initialize is up to 2 TiB in size and does not need to be subsequently extended beyond 2 TiB, you can create GPT or Master Boot Record (MBR) partitions on the data disk. For more information, see the (Conditionally required) Step 2: Create partitions on a data disk and Step 3: Create and mount a file system sections of this topic. We recommend that you create GPT partitions.
If you do not want to use partitions to manage data and you want to create a file system on the data disk as a raw device, you do not need to create partitions on the data disk. You can directly create and mount a file system on the data disk. For more information, see the Step 3: Create and mount a file system section of this topic.
(Conditionally required) Step 2: Create partitions on a data disk
Check whether a data disk needs to be initialized. For more information, see Determine the steps that you must perform to initialize the data disk.
Run commands to create partitions on the data disk that you want to initialize.
ImportantThe maximum size of a partition and the maximum number of partitions per disk vary based on the partition format. For more information, see the Partition formats section of the "Overview" topic.
If you want to subsequently extend the data disk beyond 2 TiB, partition the disk in the GPT format. If you partition the data disk in the MBR format, you cannot extend the disk beyond 2 TiB. If you extend the data disk in the MBR partition format to a size larger than 2 TiB, you may need to repartition and reformat the disk, which causes data loss.
(Recommended) Create a GPT partition
To create a GPT partition on a data disk whose size does not exceed 2 TiB by using the parted utility, perform the following steps:
Run the following command to install the parted utility:
sudo yum install -y parted
NoteThe
yum
command used in this step applies to Linux distributions such as CentOS. For other Linux distributions, modify the command based on your package management software. For example, run the following commands to install the parted utility on Debian or Ubuntu:sudo apt-get update sudo apt-get install -y parted
Use the parted utility to partition the data disk.
Run the following command to start parted on the data disk. In this example, the
/dev/vdb
data disk is used.sudo parted /dev/vdb
/dev/vdb
is the device name of the data disk that you want to partition. Replace /dev/vdb with the actual device name of your data disk.In the interactive parted shell, run the following command to set the partition format to GPT:
mklabel gpt
Run the following command to create a partition and specify the start and end positions of the partition:
mkpart <Partition name> <Start position> <End position>
ImportantSpecify the start and end positions of the partition in binary units, such as MiB and GiB, to ensure that the partition is 4 KiB-aligned. Otherwise, the partition may not be aligned, which significantly affects disk performance.
Replace <Partition name>, <Start position>, and <End position> with the actual values.
Example of creating only one partition on a data disk: Run the following command to create a primary partition named primary that starts at 1 MiB and to which 100% of the disk capacity is allocated:
mkpart primary 1MiB 100%
Example of creating multiple partitions on a data disk: Run the following command to create a partition named primary to which 20 GiB of the disk capacity is allocated and a partition named secondary to which the remaining disk capacity is allocated:
mkpart primary 1MiB 20GiB mkpart secondary 20GiB 100%
Run the following command to check whether the partition is aligned.
In the command, the number of the partition is
1
. To optimize disk performance, we recommend that you align the partition.align-check optimal 1
If the partition is aligned, the following command output is returned:
1 aligned
ImportantIf the partition is misaligned, the
1 not aligned
message is returned. For information about how to resolve the misalignment issue, see the FAQ about cloud disk initialization section of this topic.Run the following command to check the partition table:
print
(Optional) If the preceding partitioning operations are not performed as expected, run the rm <Partition number> command to delete the invalid partitions, and then reperform Steps III to V. The following figure shows how to run the print command to find an invalid partition and run the rm <Partition number> command to delete the partition. In this example, the number of the invalid partition is 2.
ImportantBefore you delete a partition, make sure that no data is stored in the partition or the data is backed up.
Run the following command to exit the parted utility:
quit
The following figure shows the partitioning process.
Run the following command to reread the partition table:
partprobe
Run the following command to view information about the new partition. In this example, the
/dev/vdb
data disk is used.sudo fdisk -lu /dev/vdb
/dev/vdb
is the device name of the data disk. Replace /dev/vdb with the actual device name of your data disk.The following command output is returned. If the new partition is created, the value of the
Disklabel type
field is gpt.NoteThe values vary based on the operating system. If the
Disklabel type
field is not displayed, check theSystem
field to determine the partition format. If the value of theSystem
field isLinux
, the MBR partition format is used. If the value of the field isGPT
, the GPT partition format is used.If you use an earlier version of fdisk, the GPT partition table may not be displayed as expected. To check the partition format, run the
gdisk -l /dev/vdb
command.
Create an MBR partition
To create an MBR partition on a data disk whose size does not exceed 2 TiB by using fdisk, perform the following steps:
Create an MBR partition.
Run the following command to start fdisk on the data disk. In this example, the
/dev/vdb
data disk is used.sudo fdisk -u /dev/vdb
/dev/vdb
is the device name of the data disk that you want to partition. Replace /dev/vdb with the actual device name of your data disk.The following command output is returned.
In the interactive fdisk shell, enter p and press the
Enter
key to view the partition information of the data disk.The following command output is returned.
Enter n and press the
Enter
key to partition the data disk.The following command output is returned.
The data disk has two types of partitions, as shown in the preceding figure.
p
: primary partition.e
: extended partition.NoteFor information about partitions, see the Partition formats section of the "Overview" topic.
In this example, only one primary partition is created. Enter p and press the
Enter
key to create a primary partition.The following command output is returned.
Partition number
indicates the number of the primary partition, which ranges from 1 to 4.Enter a partition number and press the
Enter
key.In this example, only one primary partition is created. Press the
Enter
key to use the default value1
as the number of the primary partition.The following command output is returned.
Enter a start sector number and press the
Enter
key.The
First sector
field specifies the start sector number of the partition. Valid values: 2048 to 83886079. Default value: 2048. In this example, theEnter
key is pressed to use the default value2048
as the start sector number.The following command output is returned.
NoteThe range of the start sector numbers and the range of the end sector numbers that are available for your selection are automatically displayed. You can specify a start sector number and an end sector number within the ranges or use the default values. The start sector number must be smaller than the end sector number.
Enter an end sector number and press the
Enter
key.The
Last sector
field specifies the end sector number of the partition. Valid values: 2048 to 83886079. Default value: 83886079. In this example, theEnter
key is pressed to use the default value83886079
as the end sector number.The following command output is returned.
NoteThe range of the start sector numbers and the range of the end sector numbers that are available for your selection are automatically displayed. You can specify a start sector number and an end sector number within the ranges or use the default values. The start sector number must be smaller than the end sector number.
Enter p and press the
Enter
key to view the partition information of the data disk.The following command output is returned, which contains the details of the new partition named
/dev/vdb1
.NoteIf the preceding partitioning operations are not performed as expected, enter
q
to exit fdisk. The partitioning results are not retained. You can reperform the preceding steps to partition the data disk.Enter w and press the
Enter
key to write the partitioning results to the partition table.The following command output indicates that the partition is created.
(Conditionally required) If you want to create multiple partitions on the data disk, repeat Step a.
Run the following command to view information about the new partition. In this example, the
/dev/vdb
data disk is used.sudo fdisk -lu /dev/vdb
/dev/vdb
is the device name of the data disk. Replace /dev/vdb with the actual device name of your data disk.The following command output is returned. If the new MBR partition is created,
/dev/vdb1
is displayed and the value of theDisklabel type
field is dos.NoteThe values vary based on the operating system. If the
Disklabel type
field is not displayed, check theSystem
field to determine the partition format. If the value of theSystem
field isLinux
, the MBR partition format is used. If the value of the field isGPT
, the GPT partition format is used.If you use an earlier version of fdisk, the GPT partition table may not be displayed as expected. To check the partition format, run the
gdisk -l /dev/vdb
command.
Step 3: Create and mount a file system
Before you can manage files on a data disk, you must create and mount a file system regardless of whether the disk is partitioned. Partition sizes vary based on the file system type. Create a file system based on your business requirements.
Run the following command to install e2fsprogs:
sudo yum install -y e2fsprogs
NoteThe yum command used in this step applies 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.Create a file system. In the examples, an Ext4 file system and an eXtensible File System (XFS) file system are created.
Create an Ext4 file system
For example, if you want to create an Ext4 file system on the
/dev/vdb1
partition, run the following command:sudo mkfs -t ext4 /dev/vdb1
/dev/vdb1
is the partition name of the data disk. Replace /dev/vdb1 with the actual partition name.For example, if you want to create an Ext4 file system on the
/dev/vdc
raw device, run the following command:sudo mkfs -t ext4 /dev/vdc
/dev/vdc
is the name of the raw device. Replace /dev/vdc with the actual name of your raw device.
NoteIf an error occurs when you create an Ext4 file system for a data disk whose size is 16 TiB, your e2fsprogs version may be earlier than V1.42. Upgrade your e2fsprogs version to V1.42 or later. For more information, see the How do I upgrade e2fsprogs on a Linux instance? section of this topic.
The lazy init feature of Ext4 file systems affects the I/O performance of data disks. You can disable the lazy init feature of Ext4 file systems. For more information, see the How do I disable the lazy init feature on a Linux instance? section of this topic.
Create an XFS file system
For example, run the following command to create an XFS file system on the
/dev/vdb1
partition:sudo mkfs -t xfs /dev/vdb1
/dev/vdb1
is the partition name of the data disk. Replace /dev/vdb1 with the actual partition name.For example, run the following command to create an XFS file system on the
/dev/vdc
raw device:sudo mkfs -t xfs /dev/vdc
/dev/vdc
is the name of the raw device. Replace /dev/vdc with the actual name of your raw device.
Run the following command to mount the file system.
For example, run the following command to mount the
/dev/vdb1
partition to the /mnt directory:sudo mount /dev/vdb1 /mnt
/dev/vdb1
is the partition name of the data disk. Replace /dev/vdb1 with the actual partition name./mnt
is the mount point of the partition. Replace /mnt with an existing directory that contains no data. Alternatively, run thesudo mkdir -p <New directory>
command to create a directory, and then replace /mnt with the new directory. Sample command:sudo mkdir -p /data
.ImportantIf you specify an existing directory that contains data, the data is overwritten when a file system is mounted on the directory. This may cause data loss and affect your business.
For example, if you want to mount the
/dev/vdc
raw device to the /tmp directory, run the following command:sudo mount /dev/vdc /tmp
/dev/vdc
is the name of the raw device. Replace /dev/vdc with the actual name of your raw device./mnt
is the mount point of the partition. Replace /mnt with an existing directory that contains no data. Alternatively, run thesudo mkdir -p <New directory>
command to create a directory, and then replace /mnt with the new directory. Sample command:sudo mkdir -p /data
.ImportantIf you specify an existing directory that contains data, the data is overwritten when a file system is mounted on the directory. This may cause data loss and affect your business.
Run the following command to check whether the file system is mounted as expected:
df -Th
The following command output is returned. If the file system is mounted as expected, information about the file system is displayed.
(Optional) Step 4: Configure the disk partitions to automatically mount on instance startup
If you want a disk partition to automatically mount on instance startup, write information about the disk partition to the /etc/fstab file and add the mount information of the disk partition to the /etc/fstab file.
Run the following command to back up the etc/fstab file:
sudo cp /etc/fstab /etc/fstab.bak
Write the information about the new partition to the /etc/fstab file.
sudo sh -c "echo `sudo blkid /dev/vdb1 | awk '{print \$2}' | sed 's/\"//g'` /mnt ext4 defaults 0 0 >> /etc/fstab"
Take note of the following parameters in the command:
/dev/vdb1
: the partition name of the data disk. Replace /dev/vdb1 with the actual partition name. You can run thedf -Th
command to obtain the names of partitions./mnt
: the mount point of the partition. Replace /mnt with the actual mount point. You can run thedf -Th
command to obtain the mount points of partitions.ext4
: the file system type of the partition. Replace ext4 with the type of the file system that you created. You can run thedf -Th
command to obtain the file system types of partitions.defaults
: the mount parameters of the file system. Specify mount parameters based on your business requirements. For more information, see fstab.
NoteThe Ubuntu 12.04 operating system does not support barriers. You must run the
sudo sh -c "echo `sudo blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g'` /mnt ext4 barrier=0 0 0 >> /etc/fstab"
command to write disk partition information to the /etc/fstab file.(Conditionally required) If a data disk has multiple consecutive partitions, run a command specific to each partition to write partition information to the /etc/fstab file.
For example, separately run the following commands for the
/dev/vdb
data disk that has the/dev/vdb1
and/dev/vdb2
partitions:sudo sh -c "echo `sudo blkid /dev/vdb1 | awk '{print \$2}' | sed 's/\"//g'` <Mount point of the /dev/vdb1 partition> <File system type of the /dev/vdb1 partition> defaults 0 0 >> /etc/fstab" sudo sh -c "echo `sudo blkid /dev/vdb2 | awk '{print \$2}' | sed 's/\"//g'` <Mount point of the /dev/vdb2 partition> <File system type of the /dev/vdb2 partition> defaults 0 0 >> /etc/fstab"
Run the following command to view information about the new partition in the /etc/fstab file:
cat /etc/fstab
The following command output is returned, which contains information about the
/dev/vdb1
partition.NoteIf information about the partition in the command output is incorrect, you can delete the partition information from the /etc/fstab file and add the correct partition to the file. For more information, see Configure UUIDs in the fstab file to automatically mount data disks.
Run the following commands to check whether the partition is automatically mounted:
sudo umount /dev/vdb1 sudo mount -a mount | grep /mnt
The following command output is returned. If the file system of the partition is mounted, the mount information of the file system is displayed.
FAQ about cloud disk initialization
What do I do when a GPT partition is created on a data disk but is misaligned?
How do I upgrade e2fsprogs on a Linux instance?
How do I disable the lazy init feature for a Linux instance?
References
If a cloud disk does not have sufficient storage space, you can extend the disk capacity to increase the storage space. For information about how to extend a cloud disk, see Overview.