Create and attach disks
This guide shows you how to create boot disks and data disks, attach them to virtual machines, and manage them using the evroc CLI or Kubernetes API.
For information about disks and how they work, see Disks.
Prerequisites
- Access to an evroc organization and resource group
- evroc CLI installed and configured, or kubectl configured to access the evroc Kubernetes API
Create a boot disk
A boot disk contains an operating system image that a virtual machine boots from. You must specify a disk image when creating a boot disk.
Using the CLI
Create a boot disk with the evroc compute disk create command:
evroc compute disk create mybootdisk --disk-image=ubuntu.24-04.1 --disk-storage-class=persistent
Using the API
Create a boot disk by applying a YAML configuration:
apiVersion: compute.evroclabs.net/v1alpha1
kind: Disk
metadata:
name: mybootdisk
spec:
diskSize:
amount: 100
unit: GB
diskImage:
diskImageRef:
name: ubuntu.24-04.1
diskStorageClass:
name: persistent
Apply the configuration:
kubectl apply -f bootdisk.yaml
Create a data disk
Data disks provide additional persistent storage for virtual machines. Data disks do not require a disk image, but you must specify the disk size.
Using the CLI
Create a data disk with a specific size:
evroc compute disk create mydisk --disk-storage-class=persistent --disk-size-amount=5 --disk-size-unit=GB
Using the API
Create a data disk by applying a YAML configuration:
apiVersion: compute.evroclabs.net/v1alpha1
kind: Disk
metadata:
name: mydisk
spec:
diskSize:
amount: 5
unit: GB
diskStorageClass:
name: persistent
Apply the configuration:
kubectl apply -f storagedisk.yaml
Attach a disk to an existing VM
You can attach data disks to an existing virtual machine. The VM must be stopped before attaching or detaching disks.
Using the CLI
Add a disk to an existing VM:
evroc compute vm update myvm --append --disk=mydisk
Stop the VM to apply the changes:
evroc compute vm update myvm --running=false
Wait for the VM to stop, then start it again:
evroc compute vm update myvm --running=true
Using the API
Edit the VM specification to add the disk reference to the diskRefs list:
apiVersion: compute.evroclabs.net/v1alpha1
kind: VirtualMachine
metadata:
name: myvm
spec:
diskRefs:
- name: mybootdisk
bootFrom: true
- name: mydisk
bootFrom: false
# ... other fields
Apply the updated configuration:
kubectl apply -f vm.yaml
Stop and start the VM to attach the disk:
kubectl patch virtualmachine myvm --type=merge -p '{"spec":{"running":false}}'
kubectl patch virtualmachine myvm --type=merge -p '{"spec":{"running":true}}'
Detach a disk from a VM
You can detach data disks from a virtual machine. The VM must be stopped before detaching disks.
Important: Before detaching a disk, remove its entry from
/etc/fstabon the VM to prevent boot errors.
Using the CLI
To detach a disk, update the VM with a complete list of disks that excludes the disk you want to detach. For example, if your VM has disks mybootdisk, disk1, and disk2, and you want to detach disk2:
-
Remove the disk entry from
/etc/fstabon the VM -
Stop the VM:
evroc compute vm update myvm --running=false -
Update the VM with only the disks you want to keep:
evroc compute vm update myvm --disk=mybootdisk --boot-from=true --disk=disk1 --boot-from=false -
Start the VM:
evroc compute vm update myvm --running=true
Using the API
Edit the VM specification to remove the disk from the diskRefs list:
kubectl edit virtualmachine myvm
Remove the disk entry from spec.diskRefs, then save and exit. Stop and start the VM to apply the changes:
kubectl patch virtualmachine myvm --type=merge -p '{"spec":{"running":false}}'
Wait for VM to stop.
kubectl patch virtualmachine myvm --type=merge -p '{"spec":{"running":true}}'
List disks
Using the CLI
List all disks in your resource group:
evroc compute disk list
Sample output:
Name Ready Reason Disk Image
------- ------- -------- ----------------
mybootdisk True ubuntu.24-04.1
mydisk True
Using the API
List disks using kubectl:
kubectl get disks
Sample output:
NAME READY REASON DISKIMAGE
mybootdisk True ubuntu.24-04.1
mydisk True
Delete a disk
Delete disks you no longer need. A disk must not be attached to any virtual machine before you can delete it.
Using the CLI
Delete a disk:
evroc compute disk delete mydisk
Using the API
Delete a disk using kubectl:
kubectl delete disk mydisk
Next steps
- Learn how to format and mount data disks on your virtual machines
- See the Disks API reference for complete field descriptions