Detaching a disk from a VM
You can detach a disk from either a running or a stopped VM.
Note
You cannot detach a boot disk from a VM. You cannot detach a local disk from a VM running on a dedicated host.
To successfully detach a disk from a running VM, the operating system must be ready to handle detach disk commands. Before detaching a disk, make sure the OS is booted up or stop the VM; otherwise the operation will fail. If an error occurs, stop the VM and try again.
To detach a disk from a VM:
- In the management console
, select the folder this VM belongs to. - Select Compute Cloud.
- In the left-hand panel, select
Disks. - Next to the disk in question, click
and select Detach. - Click Detach.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for detaching disks:
yc compute instance detach-disk --help
-
Get a list of VMs in the default folder:
yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4******** | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
-
Select the
ID
orNAME
of the VM, e.g.,first-instance
. -
Get a list of disks attached to the VM:
yc compute instance get --full first-instance
-
Select
disk_id
of the disk, e.g.,fhm4aq4hvq5g********
. -
Detach the disk:
yc compute instance detach-disk first-instance \ --disk-id fhm4aq4hvq5g********
If an error occurs, stop the VM:
yc compute instance stop first-instance
Then, try to detach the disk once again.
-
If the VM was stopped, restart it:
yc compute instance start first-instance
Use the detachDisk REST API method for the Instance resource or the InstanceService/DetachDisk gRPC API call.