Detach a data disk

更新时间:
复制 MD 格式

Detach a data disk from an ECS instance to migrate it to another instance or release it.

How it works

Detaching a data disk involves two steps:

  1. Unmount the file system in the operating system: Like safely ejecting a USB drive. This prevents data corruption from interrupted read/write operations during detachment.

  2. Detach the data disk from the instance: Like unplugging the USB drive after ejection. This severs the connection between the cloud disk and the ECS instance.

Usage notes

  • Subscription cloud disks cannot be detached directly. Switch the billing method to pay-as-you-go first.

  • Detaching local disks is not supported.

Procedure

Important

Before you begin, pause all read and write operations on the data disk and stop all processes using it to prevent data loss.

Detaching a data disk only separates the disk from the ECS instance. The disk remains in pay-as-you-go billing status and billing does not automatically stop. To stop billing, release the disk. Before releasing, we recommend creating a snapshot to back up the disk data.

Linux

If the instance is Stopped, you can skip to Step 2: Detach the data disk.

Step 1: Unmount the file system in the operating system

Prevent the operating system from accessing the data disk to ensure data integrity.

These standard Linux commands apply to all major distributions, such as CentOS, Ubuntu, and Debian.
  1. Log on to the ECS instance.

    1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.

    2. On the instance details page, click Connect > Workbench. Follow the prompts to log on.

  2. Run sudo df -h to find the device name in the Filesystem column and its mount point in the Mounted on column. In this example, /dev/vdb1 is mounted on /mnt.

    $ sudo df -h
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        868M     0  868M   0% /dev
    tmpfs           879M     0  879M   0% /dev/shm
    tmpfs           879M  508K  878M   1% /run
    tmpfs           879M     0  879M   0% /sys/fs/cgroup
    /dev/vda1        40G  2.4G   36G   7% /
    /dev/vdb1        40G   49M   38G   1% /mnt
    tmpfs           176M     0  176M   0% /run/user/0
  3. Unmount the file system.

    Replace <target_device_name> with the device name from the previous step.

    sudo umount <device name>
  4. Remove automatic mount configurations to prevent restart failures.

    Run cat /etc/fstab to check if the mount point from Step 2 exists.

    • If it does not exist, proceed to Step 2: Detach the data disk.

    • If it exists, run sudo vi /etc/fstab and add # at the beginning of the mount line to comment it out. Save the file and proceed to Step 2: Detach the data disk.

      In this example, comment out UUID=32532395-51a7-46f7-b83d-181158b009a0 /mnt ext4 defaults 0 0.

      # /etc/fstab
      # Created by anaconda on Fri Jun 28 04:16:23 2024
      #
      # Accessible filesystems, by reference, are maintained under '/dev/disk'
      # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
      #
      UUID=c8b5b2da-5565-4dc1-b002-2a8b07573e22 /                       ext4    defaults        1 1
      UUID=32532395-51a7-46f7-b83d-181158b009a0 /mnt ext4 defaults 0 0
      ~                                                              

Step 2: Detach the data disk

Sever the connection between the cloud disk and the ECS instance.

  1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.

  2. Click the target instance ID to go to the instance details page, and then click the Block Storage tab.

  3. In the Actions column for the target disk, click Detach.

  4. In the dialog box that appears, click OK.

  5. View the detachment result.

    Go to the ECS console > Block Storage > Cloud Disk page. The disk Status changes to Unattached, and the tag acs:ecs:lastAttachedInstance is added.

    The tag value is the last attached instance ID.

    image

Windows

  1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.

  2. Click the target instance ID to go to the instance details page, and then click the Block Storage tab.

  3. In the Actions column for the target disk, click Detach.

  4. In the dialog box that appears, select Authorize Cloud Assistant To Eject The Disk And Then Perform The Detach Operation, and then click Unmount and Detach.

    If the message An Error Occurred When Cloud Assistant Tried To Eject The Disk appears, manually unmount the file system in the operating system and then select The Disk Has Been Ejected In The Operating System to detach the data disk.
    If your instance status is Stopped, simply click OK.
  5. Verify the detachment result.

    Go to the ECS console > Block Storage > Cloud Disk page. The disk Status changes to Unattached, and the disk is tagged with acs:ecs:lastAttachedInstance.

    The tag value is the last attached instance ID.

    image

FAQ

  • What to do if the error 'An Error Occurred When Cloud Assistant Tried To Eject The Disk' appears when detaching a disk from a Windows OS?

    Cause: Cloud Assistant is not installed or is in an abnormal state.

    Solution: Manually take the disk offline, then select The Disk Has Been Ejected In The Operating System when you detach the data disk.

    This topic uses Windows Server 2022 as an example.

    1. Log on to the ECS instance.

      1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.

      2. On the instance details page, click Connect > Workbench. Set the connection method to Terminal Connection. Enter your credentials to log on to the graphical terminal.

    2. Take the disk offline.

      1. Right-click the Start icon icon and select Disk Management.

      2. In the Disk Management window, right-click the target disk and select Offline.

        Offline

  • What to do if the error 'The Following Processes Are Using The Disk. The Disk Cannot Be Ejected From The Operating System. Close The Processes And Try Again.' appears when you use Cloud Assistant to eject a disk?

    Cause: A process is using the disk. End the process before detaching.

    Solution: In this example, the process is OpenHardwareMonitor.exe (PID 6396).image

    This topic uses Windows Server 2022 as an example.

    1. Log on to the ECS instance.

      1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.

      2. On the instance details page, click Connect > Workbench. Set the connection method to Terminal. Enter your credentials to log on to the graphical terminal.

    2. Right-click the Start icon icon and select Task Manager.

    3. Click Detail. Find the target process by name or ID.

    4. Right-click the target process and click End Task. Select End Process in the dialog box. After the process ends, detach the data disk.

      Important

      Ending a process may cause data loss or business interruptions. Ensure the process is not critical and has no pending write operations.

  • What should I do if a cloud disk's status remains Detaching on a Windows instance?

    Cause: A process prevents the disk from being unmounted.

    The following steps use Windows Server 2022 as an example.

    1. Log on to the ECS instance.

      1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.

      2. On the instance details page, click Connect > Workbench. Set the connection method to Terminal. Enter your credentials to log on to the graphical terminal.

    2. Identify the process that is using the disk.

      1. Right-click the Start icon icon and select Event Viewer.

      2. In the Event Viewer window, choose Windows Logs > System.

      3. In the system logs, look for warning events to identify the name and PID of the process that is using the disk.

        In this example, the process name is OpenHardwareMonitor.exe and the PID is 3980.

        image

    3. Terminate the process.

      Important

      Terminating a process may cause data loss or service interruption. Ensure the process is not critical and has no pending write operations.

      1. Right-click the Start icon icon and select Task Manager.

      2. Click Details. Find the target process by name or ID.

      3. Right-click the target process, click End Task, and detach the data disk again.

  • View the last attached instance of a disk

    1. Navigate to ECS console - Elastic Block Storage - Disks

    2. Find disks with the Unattached status. In the Tag column, hover over the edit-tag icon.

      • If the disk has no attachment information, it has never been attached to an ECS instance.

      • If the disk has attachment information, the tag key acs:ecs:lastAttachedInstance shows the last attached instance ID.

        image

References