All Products
Search
Document Center

Elastic Compute Service:Initialize a data disk on a Linux instance

Last Updated:Feb 17, 2025

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.

    Note

    Data 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

  1. 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 .

    Requirements for using Cloud Assistant to initiate a data disk

    • Multi-attach is not enabled for the data disk.

    • The data disk is attached to a Linux ECS instance that 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.

    • You want to partition the data disk in the GUID Partition Table (GPT) format and mount Extended File System 4 (Ext4) file systems on the data disk.

    • You can use Cloud Assistant to initiate a data disk. Only specific customers can use Cloud Assistant to initiate a data disk.

  2. 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

    1. 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. 截屏2025-02-14 11

    Note

    If 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.

    1. 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. 截屏2025-01-17 09

      Note

      If 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.

    2. Configure partition information.

      截屏2024-12-25 09

      1. Specify partition sizes (Size) and mount points.

        Note

        You 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.

          Note

          Reserve 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.

          Important

          If 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.

      2. 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.

    3. (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

    1. 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. 截屏2024-11-18 11

    2. 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.截屏2025-01-17 09

    3. In the Partition and Mount Settings section, configure the Mount Point parameter and click Manually Mount to mount file systems.

      Note

      Specify an existing directory that does not contain data or create a directory as the mount point. Mount points must be unique.

      截屏2024-12-25 09

    4. (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.

    5. (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.

    6. (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

  1. Connect to the ECS instance.

  2. 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.

    截屏2025-02-12 15

  3. 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

  1. 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.

  2. Run commands to create partitions on the data disk that you want to initialize.

    Important
    • The 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:

    1. Run the following command to install the parted utility:

      sudo yum install -y parted
      Note

      The 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
    2. Use the parted utility to partition the data disk.

      1. 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.

      2. In the interactive parted shell, run the following command to set the partition format to GPT:

        mklabel gpt
      3. 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>
        Important

        Specify 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%
      4. 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
        Important

        If 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.

      5. Run the following command to check the partition table:

        print
      6. (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. 截屏2024-11-18 14

        Important

        Before you delete a partition, make sure that no data is stored in the partition or the data is backed up.

      7. Run the following command to exit the parted utility:

        quit

      The following figure shows the partitioning process.

      截屏2024-12-02 14

    3. Run the following command to reread the partition table:

      partprobe
    4. 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.

      image.png

      Note
      • The values vary based on the operating system. If the Disklabel type field is not displayed, check the System field to determine the partition format. If the value of the System field is Linux, the MBR partition format is used. If the value of the field is GPT, 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:

    1. Create an MBR partition.

      1. 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.

        image.png

      2. 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.

        image.png

      3. Enter n and press the Enter key to partition the data disk.

        The following command output is returned.

        image.png

        The data disk has two types of partitions, as shown in the preceding figure.

        • p: primary partition.

        • e: extended partition.

          Note

          For information about partitions, see the Partition formats section of the "Overview" topic.

      4. 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.

        image.png

        Partition number indicates the number of the primary partition, which ranges from 1 to 4.

      5. 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 value 1 as the number of the primary partition.

        The following command output is returned.

        image.png

      6. 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, the Enter key is pressed to use the default value 2048 as the start sector number.

        The following command output is returned.

        image.png

        Note

        The 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.

      7. 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, the Enter key is pressed to use the default value 83886079 as the end sector number.

        The following command output is returned.

        image.png

        Note

        The 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.

      8. 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.

        image.png

        Note

        If 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.

      9. 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.

        image.png

    2. (Conditionally required) If you want to create multiple partitions on the data disk, repeat Step a.

    3. 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 the Disklabel type field is dos.

      image.png

      Note
      • The values vary based on the operating system. If the Disklabel type field is not displayed, check the System field to determine the partition format. If the value of the System field is Linux, the MBR partition format is used. If the value of the field is GPT, 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.

  1. Run the following command to install e2fsprogs:

    sudo yum install -y e2fsprogs
    Note

    The 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.

  2. 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.

    Note
    • If 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.

  3. 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 the sudo mkdir -p <New directory> command to create a directory, and then replace /mnt with the new directory. Sample command: sudo mkdir -p /data.

      Important

      If 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 the sudo mkdir -p <New directory> command to create a directory, and then replace /mnt with the new directory. Sample command: sudo mkdir -p /data.

      Important

      If 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.

  4. 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.

    image

(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.

  1. Run the following command to back up the etc/fstab file:

    sudo cp /etc/fstab /etc/fstab.bak
  2. 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 the df -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 the df -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 the df -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.

    Note

    The 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.

  3. (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"
  4. 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.

    image.png

    Note

    If 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.

  5. 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.

    image

FAQ about cloud disk initialization

What do I do when a GPT partition is created on a data disk but is misaligned?

  1. 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
  2. In the interactive parted shell, run the following command to delete the invalid partition on the data disk. To query the numbers of invalid partitions, run the print command.

    Important

    Before you delete a partition, make sure that no data is stored in the partition or the data is backed up.

    rm <Partition number>
  3. Run the following command to create a partition and specify the start and end positions of the partition in MiB or GiB. For example, run the following command to create a partition named primary that starts and ends on a multiple of 1 MiB:

    mkpart primary <Start position>MiB <End position>MiB 

How do I upgrade e2fsprogs on a Linux instance?

To format a data disk whose size is 16 TiB and that has Ext4 file systems, you must use e2fsprogs V1.42 or later. If your e2fsprogs version is earlier than V1.42, the following error message is reported:

mkfs.ext4: Size of device /dev/vdb too big to be expressed in 32 bits using a blocksize of 4096.            

To install e2fsprogs V1.42 or later, perform the following steps. In this example, e2fsprogs V1.42.8 is installed.

  1. Run the following command to check your e2fsprogs version:

    rpm -qa | grep e2fsprogs

    The following command output is returned.

    查询版本

    If your e2fsprogs version is earlier than V1.42, perform the following steps to upgrade e2fsprogs.

  2. Run the following command to download e2fsprogs V1.42.8.

    You can visit the e2fsprogs website to obtain the latest software package.

    wget https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.42.8/e2fsprogs-1.42.8.tar.gz --no-check-certificate
  3. Compile the later version of e2fsprogs.

    1. Run the following command to decompress the software package:

      tar xvzf e2fsprogs-1.42.8.tar.gz
    2. Run the following command to go to the package directory:

      cd e2fsprogs-1.42.8
    3. Run the following command to generate the Makefile file:

      ./configure
    4. Run the following command to compile e2fsprogs:

      make
    5. Run the following command to install e2fsprogs:

      make install
  4. Run the following command to check whether e2fsprogs is upgraded:

    rpm -qa | grep e2fsprogs

How do I disable the lazy init feature for a Linux instance?

By default, the lazy init feature is enabled for Ext4 file systems. If the feature is enabled, the instance initiates a thread to continuously initialize the metadata of Ext4 file systems. If you format a data disk when the feature is enabled, the IOPS of the disk may be temporarily affected.

If you want to test the performance of a data disk immediately after you format the disk, run the following command to disable the lazy init feature when you format the file system:

sudo mke2fs -O 64bit,has_journal,extents,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize -E lazy_itable_init=0,lazy_journal_init=0 /dev/vdb1
Note

If the lazy init feature is disabled, an extended period of time may be required to format a disk. For example, a data disk whose size is 32 TiB may require 10 minutes to 30 minutes to be formatted. Disable the lazy init feature based on your business requirements.

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.