All Products
Search
Document Center

Elastic Compute Service:Attach a data disk

Last Updated:Jan 15, 2024

You can flexibly attach a newly purchased pay-as-you-go disk to an existing Elastic Compute Service (ECS) instance as a data disk to expand the storage capacity of the ECS instance and meet new business requirements.

Prerequisites

  • The disk and the instance to which you want to attach the disk reside in the same zone.

  • The instance is in the Running (Running) or Stopped (Stopped) state, instead of the Locked (Locked) state.

  • The disk is in the Unattached (Available) state.

  • Your Alibaba Cloud account has no overdue payments.

  • Cloud Assistant Agent is installed on the ECS instance if you want to initialize a data disk when you attach the disk to the instance. For more information, see Install Cloud Assistant Agent.

Precautions

Before you attach a disk, take note of the following items:

  • Up to 64 data disks can be attached to an ECS instance. The maximum number of disks that can be attached to an instance varies based on the instance type.

    Note

    When you create an instance, you can attach only one system disk and up to 16 data disks to the instance. If the instance requires additional data disks, attach the data disks after you create the instance. The number of disks that can be attached to an instance varies based on the instance type. You can call the DescribeInstanceTypes operation to query the number of disks that can be attached to an instance.

  • You can attach disks that do not support the multi-attach feature or disks for which the multi-attach feature is disabled only to a single instance at a time. You can attach disks that support the multi-attach feature to multiple instances at a time. For more information, see NVMe disks.

  • If a disk that contains data (such as a disk that is created from a snapshot) is attached to an ECS instance as a data disk, the attach operation does not cause data loss.

Attach a data disk

This section describes how to attach a data disk on the Instances page. Alternatively, you can attach a disk on the Disks page. In the left-side navigation pane of the ECS console, choose Storage & Snapshots > Disks and find the disk that you want to attach. In the Actions column, choose 更多 > Attach to attach the disk to an ECS instance.

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Instances & Images > Instances.

  3. In the upper-left corner of the top navigation bar, select a region. 地域

  4. Find the instance to which you want to attach a disk and click the ID of the instance.

  5. Click the Cloud Disk tab. In the upper-left corner of the Cloud Disk tab, click Attach Disks.

  6. In the Attach Disk dialog box, configure the parameters for attaching a disk.

    执行挂载

    1. Select the disk that you want to attach and configure the release settings for the disk. The following table describes the parameters.

      Parameter

      Description

      Disk

      Select the disk that you want to attach.

      Release Disk with Instance

      If you select this option, the disk is automatically released when the associated instance is released. If you do not select this option, the disk is retained when the associated instance is released.

      Note

      If the disk that you want to attach is a system disk that was detached from another instance, the instance that is specified by Release Disk with Instance refers to the instance from which the disk was detached, instead of the current instance.

      Delete Automatic Snapshots While Releasing Disk

      If you select this option, the automatic snapshots of the disk are released when the disk is released. To retain the automatic snapshots, we recommend that you do not select this option.

    2. Click Next.

      If the disk that is attached to an instance does not contain a partition or file system, the disk cannot be used. For example, you cannot view the mount information of the disk that is attached to a Linux instance by running the df -h command. To use the disk, create partitions and file systems for the disk.

  7. Use one of the following methods to create partitions and file systems for the disk based on the disk conditions.

    Note

    Whether you can initialize a disk in the ECS console is subject to information prompted in the console.

Initialize the disk in the ECS console

Only disks that meet the following conditions can be initialized in the console:

  • The disk is independently created and is a new empty disk.

  • The disk does not support the multi-attach feature.

  • The disk is attached to a Linux instance.

  • Cloud Assistant Agent is installed on the instance to which the disk is attached. For more information, see Install Cloud Assistant Agent.

image.png

Procedure

  1. In the Attach Disk dialog box, specify the size of the partitions, and the type and mount point of the file systems.

    • The size of each partition or the total size of partitions cannot exceed the disk size.

      Note

      1 MiB or 2 MiB of storage space must be reserved for the partition table and sector alignment for partitions. The partitioning feature reduces the size of the last partition to reserve the required storage space. The actual partition size may be slightly smaller than the specified partition size. The total available size of partitions may also be smaller than the disk size.

    • The disk supports only GUID Partition Table (GPT) partitions and ext4 file systems.

    • The mount point must start with a forward slash (/) and contain letters or digits. Example: /mnt. Mount points must be unique.

    You can click Create Partition to create multiple partitions on the disk based on your business requirements. You can create up to five partitions on a single disk.

  2. Select This feature is implemented by Cloud Assistant. After the disk is partitioned and formatted, files and data on its existing partitions are completely corrupted. To proceed, select this checkbox.

  3. Click OK.

    Important

    If you click Cancel, you can only run commands to initialize the disk.

    If the The disk is partitioned. message appears, the disk is initialized.

  4. Connect to the ECS instance and write the new partition information to the /etc/fstab file. This way, the partition can be automatically mounted on system startup.

    For more information, see Step 4: Configure the /etc/fstab file and mount the partition.

Initialize a disk by running commands

If the disk is a new empty data disk and cannot be initialized in the ECS console, after you attach the disk to an instance, a message appears indicating that the disk is attached and the disk enters the In Use state. To use the disk, you must log on to the instance to create partitions and file systems for the disk. The commands that are run to initialize the disk vary based on the operating system type of the instance to which the disk is attached.

Initialization-free scenarios

If the disk (such as a disk that is created from a snapshot) contains data, you do not need to initialize the disk after the disk is attached to an instance. To ensure that the disk can work as expected, perform the following operations based on the operating system type of the instance.

Important

If you want to attach the disk to the instance to which the source disk of the snapshot is attached, you must change the Universally Unique IDentifier (UUID) of the disk before you perform the mount operation. For more information, see Modify the UUID of a disk.

  • Linux instance:

    1. If the disk is attached to a Linux instance, log on to the instance and run the following command to perform the mount operation:

      mount <Disk partition name> <Mount point>
      • <Disk partition name>: You can log on to the instance to which the source disk of the snapshot is attached and run the df -h command to query the disk partition name.

      • <Partition mount point>: You can specify an existing directory as the mount point or run the mkdir -p <Mount point of the partition> command to create a directory as the mount point. The mount point must start with a forward slash (/) and contain letters or digits. Example: /mnt.

    2. Writes the new partition information to the /etc/fstab file. This way, the partition is automatically mounted on system startup.

      For more information, see Step 4: Configure the /etc/fstab file and mount the partition.

  • If the disk is attached to a Windows instance, log on to the instance and connect the disk online in the Disk Management window. For more information, see Step 1 to Step 4 in Initialize a data disk up to 2 TiB in size on a Windows instance.