Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI Studio
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Compute Cloud
    • All guides
      • Stopping and starting a VM
      • Resetting a Windows Server VM user password
      • Attaching a disk to a VM
      • Detaching a disk from a VM
      • Moving a VM to a different availability zone
      • Moving a VM to a different folder
      • Moving a VM to a different cloud
      • Adding another network interface to a VM
      • Deleting a network interface from a VM
      • Assigning a public IP address to a VM
      • Unassigning a public IP address from a VM
      • Making a VM public IP address static
      • Reassigning a public IP address from one VM to another
      • Updating the VM internal IP address
      • Updating a VM
      • Changing VM computing resources
      • Changing VM security groups
      • VM maintenance policy management
      • Configuring VM access permissions
      • Linking a service account to a VM
      • Deleting a VM
    • Viewing service resource operations
  • Yandex Container Solution
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  1. Step-by-step guides
  2. Managing a VM
  3. Detaching a disk from a VM

Detaching a disk from a VM

Written by
Yandex Cloud
Updated at June 11, 2025

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:

Management console
CLI
Terraform
API
  1. In the management console, select the folder this VM belongs to.
  2. Select Compute Cloud.
  3. In the left-hand panel, select Disks.
  4. Next to the disk in question, click and select Detach.
  5. Click Detach.

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command for detaching disks:

    yc compute instance detach-disk --help
    
  2. 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 |
    +----------------------+-----------------+---------------+---------+----------------------+
    
  3. Select the ID or NAME of the VM, e.g., first-instance.

  4. Get a list of disks attached to the VM:

    yc compute instance get --full first-instance
    
  5. Select disk_id of the disk, e.g., fhm4aq4hvq5g********.

  6. 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.

  7. If the VM was stopped, restart it:

    yc compute instance start first-instance
    

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or its mirror.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

  1. In the configuration file, delete the secondary_disk section and add the allow_stopping_for_update parameter to the yandex_compute_instance resource description:

    resource "yandex_compute_instance" "vm-1" {
      ...
      allow_stopping_for_update = true
      ...
    }
    

    Where allow_stopping_for_update is the parameter to allow your VM to stop for updates.

  2. Apply the new configuration:

    1. In the terminal, go to the directory where you edited the configuration file.

    2. Make sure the configuration file is correct using this command:

      terraform validate
      

      If the configuration is correct, you will get this message:

      Success! The configuration is valid.
      
    3. Run this command:

      terraform plan
      

      You will see a detailed list of resources. No changes will be made at this step. Terraform will show any errors found in your configuration.

    4. Apply the changes:

      terraform apply
      
    5. Type yes and press Enter to confirm the changes.

    Terraform will update all the required resources. You can check the update using the management console.

Use the detachDisk REST API method for the Instance resource or the InstanceService/DetachDisk gRPC API call.

Was the article helpful?

Previous
Attaching a disk to a VM
Next
Moving a VM to a different availability zone
Yandex project
© 2025 Yandex.Cloud LLC