Detach a data disk

更新时间:
复制 MD 格式

You can detach a data disk from an Elastic Compute Service (ECS) instance to attach it to another instance or to release it. Detaching a disk enables flexible data migration and efficient management of your storage resources.

How it works

Detaching a data disk involves two main steps:

  1. Unmount the file system in the operating system: This is analogous to safely ejecting a USB drive before unplugging it. This action sends an unmount command to the operating system to prevent data corruption from interrupted read/write operations during detachment.

  2. Detach the data disk from the instance: This is like physically unplugging the USB drive after it has been safely ejected. This action severs the connection between the cloud disk and the ECS instance.

Usage notes

  • You cannot directly detach a subscription-based cloud disk. First switch the billing method to pay-as-you-go before detaching the disk.

  • Detaching local disks is not supported.

Procedure

Important

To prevent data loss, pause all read and write operations on the data disk and stop any processes that are using it before you begin.

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

To ensure data integrity, you must first prevent the operating system from accessing the data disk.

The following instructions are standard Linux commands and 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 navigation bar, select the target region and resource group.

    2. On the instance details page, click Connect and select Workbench. Follow the on-screen prompts to log on to the terminal.

  2. Run the sudo df -h command to find the target device name in the Filesystem column and its mount point from the Mounted on column.In this example, the target device /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 you obtained in the previous step, and then run the command.

    sudo umount <device name>
  4. Check for and remove any automatic mount configurations to prevent the instance from failing to restart.

    Use the cat /etc/fstab command to check if the mount point information from Step 2 exists.

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

    • If it exists, run the sudo vi /etc/fstab command to edit the file. Add a # symbol at the beginning of the line that contains the mount directory to comment it out. Save the file, and then proceed to Step 2: Detach the data disk.

      In this example, you need to comment out the line 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

Detach the data disk from the ECS instance to sever the connection between the disk and the instance.

  1. Go to ECS console - Instances. In the top navigation bar, select the target region and resource group.

  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. Verify that the disk is detached.

    Go to the ECS console -Block Storage - Cloud Disk page to check the disk status. If the disk Status changes to Unattached, the disk is successfully detached.

Windows

  1. Go to ECS console - Instances. In the top navigation bar, select the target region and resource group.

  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 Eject 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 Confirm Detach.
  5. You can verify that the uninstallation was successful.

    After the detachment is complete, go to the ECS console - Elastic Block Storage - Disks page to check the disk status. If the disk Status changes to Available, the disk is successfully detached.

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: This error usually occurs because Cloud Assistant is not installed or is in an abnormal state.

    Solution: You can manually take the disk offline in the operating system. Then, in the console, 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 navigation bar, select the target region and resource group.

      2. Go to the instance details page. Click Remote Connection and select Connect Via Workbench. Set the connection method to Terminal Connection. Enter your username and password to log on to the graphical terminal.

    2. Take the disk offline.

      1. Right-click the 开始图标 icon and select Disk Management.

      2. In the Disk Management window, right-click the target disk and select 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 currently using the disk. You must manually end the process before you can detach the disk.

    Solution: In this example, the process to be ended is OpenHardwareMonitor.exe, and its ID is 6396.

    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 navigation bar, select the target region and resource group.

      2. Go to the instance details page. Click Connect and select Workbench. Set the connection method to Terminal. Enter your username and password to log on to the graphical terminal.

    2. Right-click the 开始图标 icon and select Task Manager.

    3. Click Details. Find the process to be ended by its name or ID.

    4. Right-click the target process and click End Task. In the dialog box that appears, select End Process. After the process ends, detach the data disk.

      Important

      Ending a process may cause data loss or business interruptions. Evaluate the risks carefully. Make sure the process is not critical and is not writing data.

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

    Cause: This usually happens when a process prevents the disk from being unmounted. The solution is to log on to the instance and manually stop the process.

    Solution:

    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 navigation bar, select the target region and resource group.

      2. Go to the instance details page. Click Connect and select Workbench. Set the connection method to Terminal. Enter your username and password to log on to the graphical terminal.

    2. Identify the process that is using the disk.

      1. Right-click the 开始图标 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 carries a risk of data loss or service interruption. Evaluate the impact carefully and ensure the process is not critical and has no pending write operations.

      1. Right-click the 开始图标 icon and select Task Manager.

      2. Click More Details. Find the process to be ended by its name or ID.

      3. Right-click the target process and click End Task. Then try to detach the data disk again.

References