Detaching a disk from a VM

    To detach a disk from a VM:

    If you don't have the Yandex.Cloud command line interface yet, install it.

    The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id flag.

    1. View a description of the CLI's detach disk command:

      $ yc compute instance detach-disk --help
      
    2. Get a list of VMs in the default folder:

      $ yc compute instance list
      +----------------------+-----------------+---------------+---------+----------------------+
      |          ID          |       NAME      |    ZONE ID    | STATUS  |     DESCRIPTION      |
      +----------------------+-----------------+---------------+---------+----------------------+
      | fhm0b28lgfp4tkoa3jl6 | first-instance  | ru-central1-a | RUNNING | my first vm via CLI  |
      | fhm9gk85nj7gcoji2f8s | second-instance | ru-central1-a | RUNNING | my second vm via CLI |
      +----------------------+-----------------+---------------+---------+----------------------+
      
    3. Select the ID or NAME of the VM you need (for example, first-instance).

    4. Stop the VM:

      $ yc compute instance stop first-instance
      
    5. Get a list of disks attached to the VM:

      $ yc compute instance get --full first-instance
      
    6. Choose the disk_id of the disk you need (for example, fhm4aq4hvq5g3nepvt9b).

    7. Detach the disk:

      $ yc compute instance detach-disk first-instance \
          --disk-id fhm4aq4hvq5g3nepvt9b
      
    8. Start the VM:

      $ yc compute instance start first-instance
      

    Use the detachDisk method for the Instance resource.