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
-
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 fromvdatovdz, andvdcis reserved by the platform. Omitted, the platform assigns the first free name. -
Check the attachment in the instance’s
volumeAttachments:terminal origin compute get-instance --instance-urn <instance-urn>- On a stopped instance, the attachment reads
ATTACHEDright 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, thenATTACHEDonce the guest sees the device. If the device can’t be added, it readsFAILEDand the volume is released.
- On a stopped instance, the attachment reads
-
Verify inside the guest that the disk is there, under the attachment’s
deviceName:terminal lsblkA new volume has no file system. Create one before you mount it.
Detach a volume
-
Unmount the file system inside the guest if the instance is running.
-
Detach the volume:
terminal origin compute detach-volume \ --instance-urn <instance-urn> \ --volume-urn <volume-urn>On a running instance the attachment reads
DETACHINGuntil the guest releases the device. If the guest doesn’t release it, the attachment returns toATTACHEDand the volume stays attached. -
Verify that the volume reads
AVAILABLE:terminal origin storage get-volume --volume-urn <volume-urn>The attachment stays in the instance’s
volumeAttachmentshistory asDETACHED, 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:
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.