Attach disks to running VMs
This guide shows you how to attach and detach disks from running virtual machines without stopping them, using hotswap disk attachments.
For information about how hotswap attachments work, see Hotswap Disk Attachments.
Prerequisites
- An evroc account with an active project
- The evroc CLI installed and configured
- A running VM
- A data disk in the same zone as the VM
Hotswap vs permanent attachments
VMs have two ways to attach disks:
- Permanent disks are specified when the VM is created, or added while the VM is stopped. To change a permanent disk, you must stop the VM first.
- Hotswap attachments can be created and deleted while the VM is running. The disk attaches or detaches immediately without interrupting the VM.
Use hotswap attachments when you need to dynamically add or remove storage from a running VM, for example when using Kubernetes persistent volumes or when transferring data between VMs.
Create a hotswap disk attachment
Create a hotswap disk attachment to attach a disk to a running VM:
evroc compute hotswapdiskattachment create my-attachment \
--disk-ref=my-data-disk \
--vm-ref=my-vm
The disk attaches immediately. The attachment persists across VM restarts—the disk is automatically reattached when the VM starts.
See Create a HotswapDiskAttachment in the API reference.
Important: The disk and VM must be in the same zone. A disk can only be attached to one VM at a time, whether as a permanent disk or hotswap attachment.
View attachment details
Get details about a hotswap disk attachment, including its serial number:
evroc compute hotswapdiskattachment get my-attachment
The output includes a serial number that you can use to identify the disk inside the VM.
See Get a HotswapDiskAttachment in the API reference.
Identify the disk inside the VM
Hotswap disks use the SCSI bus and can be identified by their serial number. The serial number is reported in the attachment status.
Inside the VM, the disk is available at:
/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_<SERIAL>
For example, if the attachment's serial is hs-my-data-disk, the device path is:
/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_hs-my-data-disk
You can also use lsblk to see the attached disk:
lsblk
The hotswap disk appears as a new block device (typically sda, sdb, etc., as SCSI devices use different naming than virtio devices).
List hotswap disk attachments
List all hotswap disk attachments in your project:
evroc compute hotswapdiskattachment list
See Get HotswapDiskAttachments in the API reference.
Delete a hotswap disk attachment
Delete the attachment to detach the disk from the VM:
evroc compute hotswapdiskattachment delete my-attachment
The disk detaches immediately and becomes available for use elsewhere.
See Delete a HotswapDiskAttachment in the API reference.
Important: Before detaching a disk, unmount it inside the VM to prevent data corruption. If you've added the disk to
/etc/fstab, remove that entry to prevent boot errors if the VM restarts.
Constraints
- A disk can only be attached to one VM at a time (whether permanent or hotswap)
- A disk can't be both permanently attached and hotswap-attached to the same VM
- The disk and VM must be in the same zone
- Disks attached via hotswap can't be deleted until the attachment is removed
- Each VM can have up to 255 hotswap disk attachments
Next steps
- Learn about hotswap disk attachment concepts for more details on how they work
- See how to create and attach disks as permanent attachments
- Learn how to format and mount disks once attached