Attach and detach a volume

Attach a volume to a virtual machine from the volume list or from the instance's Disks tab, prepare it in the operating system, and detach it again.

Attach a volume to an instance to use it as a disk, and detach it to release it. A volume is attached to one instance at a time, and both must be in the same project.

Before you begin

  • You need the Owner or Contributor role, or a custom role with Manage access to Block & Object Storage, on the subscription or on the project.
  • To attach a volume, its status must be Available, and it must not be attached to another instance.

Attach a volume

In the console, go to StorageVolumes.

Open the actions menu (⋯) at the end of the volume's row, and select Attach.

In Instance, select the instance, and select Attach.

When the attachment finishes, the volume's status is In use, and the volume list shows the instance and the device path that the cloud reported, such as /dev/vdc. You can also attach a new volume when you create it. See Create a volume.

To attach with the API, use POST/scopes/{scopeId}/storage/volumes/{volumeId}/actions/attach. If you don't name a device path, the platform assigns the next free one.

Use the volume in the operating system

The operating system sees the attached volume as a new disk.

  • A new, empty volume has no file system. Create one, and mount it, before you store data on it. For the commands on Linux, see Quickstart: Create and attach a volume.
  • A volume that already has a file system, for example one that you detached from another instance, only needs to be mounted.

Find the disk by its size, for example with lsblk on Linux.

Detach a volume

Important

Before you detach a volume from a running instance, stop the applications that use it, and unmount its file systems in the operating system. Detaching a mounted volume can lose data that wasn't written to the disk yet.

In the console, go to StorageVolumes.

Open the actions menu (⋯) at the end of the volume's row, and select Detach.

When the detachment finishes, the volume's status is Available. Its data stays on the volume, and you can attach it to another instance.

You can't detach the OS disk of an instance. For the OS disk, the console shows the detach action as unavailable and explains why.

Rules

RuleDetails
Volume status for an attachAvailable. A volume that's attached, still being created, or in error can't be attached.
Instances per volumeOne at a time.
ProjectThe volume and the instance must be in the same project.
OS diskCan't be detached while the instance exists. It's released when you delete the instance.

Troubleshooting

MessageCauseWhat to do
"volume must be AVAILABLE to attach"The volume is attached, still being created, or in error.Wait until the volume is Available, or detach it from the other instance first.
"volume is not attached to any instance"The volume was already detached.No action is needed.
This is the instance’s root volume — it can’t be detached while the instance exists. Delete the instance to release it.The volume is the instance's OS disk.Keep it attached. To release it, delete the instance. See Delete an instance.

If an attach or a detach fails on the cloud, the console shows a notification, and the volume's Activity tab lists the failed operation with its reason.

On this page