All Products
Search
Document Center

Elastic Compute Service:Detach a data disk

Last Updated:Nov 20, 2024

You can detach a data disk from an Elastic Compute Service (ECS) instance when the disk is no longer needed. You must detach a data disk from an instance before you can attach the disk to another instance within the same zone. This topic describes how to detach a data disk.

Prerequisites

Before you detach a data disk, make sure that the following conditions are met:

  • The data disk is attached to an instance and In Use is displayed in the Status column that corresponds to the disk in the ECS console.

  • To prevent data loss and ensure data integrity, we recommend that you stop read and write operations on the data disk before you detach the disk.

Workflow

The following figure shows the workflow of detaching a data disk.

image
Note

You cannot detach local disks that are used as data disks.

  1. If the data disk that you want to detach uses the subscription billing method, change the billing method of the disk to pay-as-you-go.

    For more information, see the (Optional) Step 1: Change the billing method of the data disk from subscription to pay-as-you-go section in this topic.

  2. If file systems are mounted to the partitions of the data disk, detach the data disk from within the operating system of the instance to which the data disk is attached.

    For more information, see the Step 2: Detach the data disk from within the operating system of the instance to which the disk is attached section in this topic.

  3. Detach the data disk in the ECS console.

    For more information, see the Step 3: Detach the data disk in the ECS console section in this topic.

Procedure

(Optional) Step 1: Change the billing method of the data disk from subscription to pay-as-you-go

If your data disk uses the pay-as-you-go billing method, skip this step.

If your data disk uses the subscription billing method, you cannot detach the data disk, as shown in the following figure. You must change the billing method of the data disk to pay-as-you-go before you can detach the disk. For more information, see the Change the billing method from subscription to pay-as-you-go section in the "Change the billing method of a disk" topic.包年包月

Step 2: Detach the data disk from within the operating system of the instance to which the disk is attached

If the data disk is partitioned and has file systems mounted, perform the following operations to detach the data disk from within the operating system of the instance to which the disk is attached:

For a Linux instance, perform the following steps:

  1. Connect to the Linux instance.

  2. Run the following command to view the mount information of the data disk:

    df -h

    The following sample command output is displayed. In this example, the /dev/vdb1 partition of the data disk is used. In actual scenarios, select the data disk partitions whose mount information you want to view.查询挂载

  3. Run the umount command to unmount the file systems from the data disk partitions.

    For example, you can run the following command to unmount the file system from the /dev/vdb1 partition of the data disk:

    umount /dev/vdb1
  4. Run the following command to view the UUID information of the data disk partitions:

    blkid

    The following sample command output shows the UUID information of the /dev/vdb1 partition of the data disk.blkid

  5. Run the following command to check whether the /etc/fstab file contains the automatic mount configuration information of the file systems in the data disk partitions:

    cat /etc/fstab

    Find the UUID information you obtained in the previous step in the command output. The file system mounted to the /dev/vdb1 partition is configured in /etc/fstab, as shown in the following figure.fstab

  6. Delete the automatic mount configuration information of the file systems in the data disk partitions from /etc/fstab.

    Note

    If you do not delete the automatic mount configuration information of the file systems in the data disk partitions from /etc/fstab, the instance cannot be restarted after you detach the data disk from the instance in the ECS console.

    1. Run the following command to edit /etc/fstab:

      vim /etc/fstab
    2. Press the I key to enter the Insert mode.

    3. Delete or comment out the automatic mount configuration information of the file systems in the data disk partitions.

      For example, you can add # before the line of the automatic mount configuration information to comment out the configuration information, as shown in the following figure.注释

    4. Press the Esc key, enter :wq, and then press the Enter key to save your changes and exit the Insert mode.

For a Windows instance, perform the following steps:

  1. Connect to the Windows instance.

  2. On the Windows Server desktop, right-click the 开始图标 icon and select Disk Management.

  3. In the Disk Management dialog box, right-click the disk that you want to detach and select Offline.

    脱机

Step 3: Detach the data disk in the ECS console

You can detach the data disk on the Instance or Disks page. Perform the following steps to detach the data disk on the Instance page in the ECS console:

  1. Log on to the ECS console.

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

  3. In the top navigation bar, select the region and resource group to which the resource belongs. 地域

  4. Find the instance from which you want to detach the data disk and click the instance ID.

  5. On the Instance Details page, click the Block Storage tab.

  6. Find the data disk that you want to detach and choose 更多 > Detach in the Actions column.

    Note

    If No is displayed in the Removable column, the data disk cannot be detached. In this case, perform the operations that are described in the (Optional) Step 1: Change the billing method of the data disk from subscription to pay-as-you-go section of this topic to change the billing method of the disk.

  7. In the Detach Disk message, click OK.

    Important

    If the disk is already offline from the Windows instance but an error is reported when you detach the disk in the ECS console, this may be because programs on the instance are accessing the data or information of the disk. We recommend that you restart the instance, take the disk offline, and then detach the disk in the ECS console. Instance restart may interrupt services. We recommend that you restart the instance during an appropriate period of time.

    After you perform the preceding steps to detach the data disk, you can find the disk on the Block Storage page. If Unattached is displayed in the Status column, the disk is detached.

References

  • You can call an API operation to detach a pay-as-you-go data disk from an ECS instance. For more information, see DetachDisk.

  • You can attach the data disk that was detached from an instance to another instance within the same zone. For more information, see Attach a data disk.

  • If you no longer need the data disk that you detached, you can back up data stored on the disk and then release the disk. For more information, see Create a snapshot and Release a disk.