Attaching and detaching volumes
Limitations
- You can only attach and detach non-boot volumes.
Prerequisites
- A volume is created, as described in Creating and deleting volumes.
- To be able to use volumes attached to VMs, they must be initialized inside the guest OS by standard means.
To attach a volume to a virtual machine
Admin panel
Command-line interface
Use the following command:
vinfra service compute server volume attach --server <server> <volume>
--server <server>
- Virtual machine ID or name
<volume>
- Volume ID or name
For example, to attach the available volume with the ID e4cb5363-1fb2-41f5-b24b-18f98a388cba
to the virtual machine myvm
, run:
# vinfra service compute server volume attach e4cb5363-1fb2-41f5-b24b-18f98a388cba --server myvm +--------+--------------------------------------+ | Field | Value | +--------+--------------------------------------+ | device | /dev/vdb | | id | e4cb5363-1fb2-41f5-b24b-18f98a388cba | +--------+--------------------------------------+
The name of the new device will be shown in the command output. To see all of the VM volumes, run:
# vinfra service compute server volume list --server myvm +--------------------------------------+----------+ | id | device | +--------------------------------------+----------+ | e4cb5363-1fb2-41f5-b24b-18f98a388cba | /dev/vdb | | b325cc6e-8de1-4b6c-9807-5a497e3da7e3 | /dev/vda | +--------------------------------------+----------+
To detach a volume from a virtual machine
Admin panel
- On the Compute > Storage > Volumes screen, click a volume that is in use.
- If the VM is stopped, click Detach on the volume right pane.
-
If the VM is running, click Force detach on the volume right pane.
There is a risk of data loss.
Command-line interface
Use the following command:
vinfra service compute server volume detach [--force] --server <server> <volume>
--server <server>
- Virtual machine ID or name
--force
- Detach a volume without checking if either the volume or server exists. When specifying the volume and server, use their IDs. No name lookup is performed.
<volume>
- Volume ID or name
For example, to detach the volume with the ID e4cb5363-1fb2-41f5-b24b-18f98a388cba
from the virtual machine myvm
, run:
# vinfra service compute server volume detach e4cb5363-1fb2-41f5-b24b-18f98a388cba \ --server 871fef54-519b-4111-b18d-d2039e2410a8