All Products
Search
Document Center

:How do I restore system disk data?

Last Updated:Dec 26, 2022

When you cannot connect to an Elastic Compute Service (ECS) instance by using SSH or Virtual Network Computing (VNC) due to file damage, you can detach the system disk from the instance and attach the disk to another instance as a data disk to repair the disk.

Background information

In this topic, Instance A is an abnormal instance whose system disk must be detached, and Instance B is an instance that can be connected as expected.

Step 1: Create snapshots

We recommend that you create snapshots for the system disk of Instance A to improve fault tolerance. For information about the prerequisites and background information for creating snapshots, see Create a snapshot of a disk.

  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. On the Instances page, find Instance A and click the ID of the instance.

  5. On the Instance Details page, click the Cloud Disk tab.

  6. Find the system disk and click Create Snapshot in the Actions column.

    In the Create Disk Snapshot dialog box, configure parameters to create a snapshot of the disk. For information about the parameters, see Create a snapshot of a disk.Create Snapshot (International site)

  7. On the Instance Details page, click the Snapshot tab to view the snapshot creation task.

    If the snapshot is created, 100% is displayed in the Progress column that corresponds to the snapshot.

Step 2: Detach the system disk from Instance A

After the snapshot is created, stop Instance A and then perform the following steps to detach the system disk from Instance A.

Important

For information about the prerequisites and background information for detaching a system disk, see Detach or attach a system disk.

  1. Log on to the ECS console.

  2. Stop Instance A.

    For more information, see Stop an instance.

  3. On the Instance Details page of Instance A, click the Cloud Disk tab.

  4. Find the system disk that you want to detach. In the Actions column, choose More > Detach.

    Note

    If you clear Release Disk with Instance in the Detach Disk dialog box, the system disk is retained as a pay-as-you-go data disk when the instance is released.

  5. In the Detach Disk dialog box, click OK.

  6. Check whether the system disk is detached from Instance A.

    • Go back to the Instances page. If the system disk is detached from Instance A, No System Disk is displayed in the Status column that corresponds to the instance and a tag whose value is the ID of the system disk is added to the instance.

    • In the left-side navigation pane, choose Storage & Snapshots > Disks. On the Disks page, select Disk ID from the drop-down list, enter the ID of the system disk in the search box, and then click the Search icon.

      The system disk that was detached from Instance A is in the Unattached state.

    • The system disk is converted into a data disk, three tags are added to the disk, and the billing method of the disk remains unchanged.

    You can use the tags that are added to the instance and to the disk to search for resources. The following table describes the tags.

    Tag key

    Description of the tag key

    Tag value

    acs:ecs:sourceSystemDiskId

    The system disk of the instance.

    The ID of the disk.

    acs:ecs:sourceInstanceId

    The instance from which the system disk was detached.

    The ID of the instance.

    acs:ecs:diskDeleteProtection

    The release protection feature is enabled for the disk. The disk cannot be manually released.

    true

    acs:ecs:diskPayType

    The billing method of the disk.

    The billing method of the disk before it is detached. Valid values:

    • Prepaid: subscription

    • AfterPay: pay-as-you-go

Step 3: Attach the system disk that was detached from Instance A to Instance B as a data disk

After the system disk is detached from Instance A, perform the following steps to attach the disk as a data disk to Instance B. Assume that the disk is Disk C.

Important

For information about prerequisites and background information for attaching a data disk, see Attach a data disk.

  1. Log on to the ECS console.

  2. On the Instance Details page of Instance B, click the Cloud Disk tab.

  3. On the Cloud Disk tab, click Attach Disks.

  4. In the Attach Disk dialog box, complete the following settings:

    1. Select Disk C and configure the release settings for the disk.

      Attach the disk to Instance B
    2. Click Next. Then, click OK.

      If the disk is attached to Instance B, In Use is displayed in the Status column that corresponds to the disk.

    3. If Instance B is a Linux instance, view the UUID of Disk C.

      If the UUID of Disk C is the same as that of an existing data disk on Instance B, this UUID conflict may cause a failure to attach Disk C to the instance. If this occurs, we recommend that you attach Disk C to a different instance. For information about how to view the UUID of a disk, see the description of the blkid command in Modify the UUID of a disk.

      Note

      You attach the system disk that was detached from Instance A to Instance B as a data disk to repair the disk. After the disk is repaired, you must re-attach the disk to Instance A. Therefore, do not modify the UUID of the disk.

  5. Log on to Instance B by using SSH or VNC.

    For more information, see Connection methods.

  6. Run the following command to attach Disk C to Instance B as a data disk:

    mount <Data disk partition> <Mount point>
    • <Data disk partition>: After you run the lsblk command and the blkid command on Instance B, the partitions and file systems of Disk C are found on Instance B. For example, if the root file system of Disk C is /dev/vdb1, set <Data disk partition> to /dev/vdb1.

      Note

      After Disk C is attached to Instance B, Instance B reads the partitions of the disk and mounts the disk as a data disk after the existing disks of instance B.

    • <Mount point>: You must prepare a directory as the mount point of Disk C. The directory can be an existing directory such as /mnt in Instance B or a new directory that is created in the /tmp directory or a temporary directory.

      Important

      The directory must be empty without file systems mounted.

    If the data disk partition is /dev/vdb1 and the mount point is /mnt, run the following command:

    mount /dev/vdb1 /mnt

Step 4: Perform repair operations

You can perform operations on Instance B to repair Disk C. After the repair operations are complete, run the exit command to exit the chroot environment. To repair the disk, perform the following operations:

  1. Log on to Instance B by using SSH or VNC.

    For more information, see Connection methods.

  2. Run the following command to switch the root directory to the /mnt directory:

    chroot /mnt
    Note

    If the chroot command fails to run, the cause of the failure may be that the Bash environment in Disk C is damaged.

  3. In the chroot environment of Instance B, resolve the issues that occur on Disk C.

    For information about the descriptions, causes, and solutions of the issues, see corresponding documentation.

  4. Run the exit command to exit the chroot environment.

Step 5: Re-attach Disk C to Instance A

If you have repaired Disk C on Instance B and want to re-attach Disk C to Instance A, detach Disk C from Instance B and then re-attach Disk C to Instance A. Perform the following operations:

  1. Detach Disk C from Instance B.

    For more information, see Detach a data disk.

  2. Re-attach Disk C to Instance A.

    For more information, see the "Detach a system disk" section of Detach or attach a system disk.