Skip to content

Compute / Task

Attach and detach volumes

Updated · 3 min read

Attach an available volume to a running or stopped instance, choose its guest device name, and detach it again to use elsewhere.

On this page6 sections

Attach a volume to give an instance another disk. Detach it to move the disk and its data to another instance. The instance can be running or stopped.

Before you begin

Attach a volume

  1. Attach the volume:

    terminal
    origin compute attach-volume \
      --instance-urn <instance-urn> \
      --volume-urn <volume-urn>

    To choose the guest device name, add --device-name, for example --device-name vdb. Names run from vda to vdz, and vdc is reserved by the platform. Omitted, the platform assigns the first free name.

  2. Check the attachment in the instance’s volumeAttachments:

    terminal
    origin compute get-instance --instance-urn <instance-urn>
    • On a stopped instance, the attachment reads ATTACHED right away and the disk appears in the guest at the next start.
    • On a running instance, the disk is added live. The attachment reads ATTACHING, then ATTACHED once the guest sees the device. If the device can’t be added, it reads FAILED and the volume is released.
  3. Verify inside the guest that the disk is there, under the attachment’s deviceName:

    terminal
    lsblk

    A new volume has no file system. Create one before you mount it.

Detach a volume

  1. Unmount the file system inside the guest if the instance is running.

  2. Detach the volume:

    terminal
    origin compute detach-volume \
      --instance-urn <instance-urn> \
      --volume-urn <volume-urn>

    On a running instance the attachment reads DETACHING until the guest releases the device. If the guest doesn’t release it, the attachment returns to ATTACHED and the volume stays attached.

  3. Verify that the volume reads AVAILABLE:

    terminal
    origin storage get-volume --volume-urn <volume-urn>

    The attachment stays in the instance’s volumeAttachments history as DETACHED, with its volume reference cleared.

You can’t detach an instance’s root disk.

Using the API

The attachVolume and detachVolume mutations return the attachment:

GraphQL
mutation {
  compute {
    attachVolume(input: {
      instanceUrn: "<instance-urn>"
      volumeUrn: "<volume-urn>"
      deviceName: "vdb"
    }) {
      urn
      deviceName
      status
    }
  }
}

If this fails

An attach is refused when the instance is neither running nor stopped, when the volume isn’t AVAILABLE, or when the device name you asked for is already taken. To find which instance holds a volume that reads INUSE, see Find the instance that holds a volume.