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.
Log on to the ECS console.
In the left-side navigation pane, choose Instances & Images > Instances.
In the upper-left corner of the top navigation bar, select a region.
On the Instances page, find Instance A and click the ID of the instance.
On the Instance Details page, click the Cloud Disk tab.
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.
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.
For information about the prerequisites and background information for detaching a system disk, see Detach or attach a system disk.
Stop Instance A.
For more information, see Stop an instance.
On the Instance Details page of Instance A, click the Cloud Disk tab.
Find the system disk that you want to detach. In the Actions column, choose More > Detach.
NoteIf 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.
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.
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.
For information about prerequisites and background information for attaching a data disk, see Attach a data disk.
Log on to the ECS console.
On the Instance Details page of Instance B, click the Cloud Disk tab.
Log on to Instance B by using SSH or VNC.
For more information, see Connection methods.
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 theblkid
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.NoteAfter 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.
ImportantThe 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:
Log on to Instance B by using SSH or VNC.
For more information, see Connection methods.
Run the following command to switch the root directory to the
/mnt
directory:chroot /mnt
NoteIf the
chroot
command fails to run, the cause of the failure may be that the Bash environment in Disk C is damaged.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.
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:
Detach Disk C from Instance B.
For more information, see Detach a data disk.
Re-attach Disk C to Instance A.
For more information, see the "Detach a system disk" section of Detach or attach a system disk.