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 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 avoid data loss and ensure data integrity, we recommend that you stop read and write operations on the disk before you detach it.

Background information

The following figure shows the procedure to detach a data disk.Procedure
Note Local disks that are used as data disks cannot be detached.
  1. If the data disk that you want to detach uses the subscription billing method, change its billing method to pay-as-you-go.

    For more information, see Step 1: Change the billing method of the data disk from subscription to pay-as-you-go.

  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 Step 2: Detach the data disk from within the operating system of the instance to which the disk is attached.

  3. Detach the data disk in the ECS console.

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

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, the data disk cannot be detached, shown as in the following figure. You must change the billing method of your data disk to pay-as-you-go. For more information, see Change the billing method from subscription to pay-as-you-go. Subscription

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
    A command output similar to the following one is displayed. In this example, the /dev/vdb1 partition of the data disk is used. In actual scenarios, choose the data disk partitions whose mount information you want to view. View the mount information
  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 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 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 edit 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 it out. Comment out
    4. Press the Esc key, enter :wq, and then press the Enter key to save your changes and exit the edit mode.

For a Windows instance, perform the following steps:

Note In this example, Windows Server 2012 R2 is used.
  1. Connect to the Windows instance.
  2. On the Windows Server desktop, click the Server Manager icon in the lower-left corner.
    Server Manager
  3. In the upper-right corner of the Server Manager window, choose Tools > Computer Management.
  4. In the left-side navigation pane, choose Computer Management (Local) > Storage > Disk Management.
  5. Right-click the disk that you want to detach and select Offline.
    Offline

Step 3: Detach the data disk in the ECS console

You can detach the data disk on the Instances or Disks page. Perform the following operations to detach the data disk on the Instances 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 a region.
  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 Cloud Disk tab.
  6. Find the data disk that you want to detach and choose More > Detach in the Actions column.
    Note If No is displayed in the Detachable(All) column, the data disk cannot be detached. In this case, go to Step 1: Change the billing method of the data disk from subscription to pay-as-you-go.
  7. In the Detach Disk dialog box, click OK.

You can also choose Storage & Snapshots > Disks to go to the Disks page to detach the data disk.

Result

After you perform the preceding steps to detach the data disk, you can choose Storage & Snapshots > Disks to find the disk on the Disks page. If Unattached is displayed in the Status(All) column, the disk is detached.

What to do next

  • You can attach the data disk to another instance within the same zone. For more information, see Attach a data disk.
  • When the data disk is no longer needed, you can back up data stored on the disk and then release the disk. For more information, see Create a snapshot for a disk and Release a disk.