Managing Virtual Disks
Data disks can be used to meet the data persistence requirements of the business.
A data disk is backed by a CDI DataVolume (which provisions a PVC of the same name). The operations below map to: create a DataVolume, hot-plug it to a virtual machine (addvolume), expand its PVC, detach it (removevolume), and delete the DataVolume.
TOC
Creating a Virtual DiskProceduresUsing the APIMounting a Virtual DiskProceduresUsing the APIExpanding a Virtual DiskProceduresUsing the APIUnmounting a Virtual DiskProceduresUsing the APIDeleting a Virtual DiskProceduresUsing the APIStorageProfile and cross-namespace clone scopeCreating a Virtual Disk
Create a data disk for the virtual machine. Only one virtual disk can be added at a time; if multiple disks are needed, please repeat this operation.
Note: Virtual disks can be mounted online when the virtual machine is in running state.
Procedures
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Disk.
-
Click on Create Virtual Disk.
-
Configure the information based on the following instructions.
-
Click on Create.
Using the API
Create a blank data disk as a DataVolume:
Mounting a Virtual Disk
Mount the data disk to a virtual machine, attaching the already created virtual disk to the target virtual machine.
Note: Virtual disks can be mounted online when the virtual machine is in running state.
Procedures
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Disk.
-
Click ⋮ > Mount next to the virtual disk to be mounted.
-
Select the target virtual machine and click Mount.
Using the API
Hot-plug the disk into a running virtual machine. With virtctl, use --persist so the disk is added to the virtual machine spec and survives a restart:
This issues the addvolume subresource request (AddVolumeOptions). The disk then appears in VirtualMachineInstance.status.volumeStatus and progresses from AttachedToNode to Ready. Without --persist, the hot-plug applies to the running instance only and does not survive a restart.
Expanding a Virtual Disk
Expand the system disk and data disk already mounted to the virtual machine.
Procedures
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Machine.
-
Click the name of the virtual machine to enter the Details page.
-
In the Virtual Disk area, find the disk to be expanded and click ⋮ > Expand.
-
Enter the new capacity and click Expand.
Using the API
Patch the PVC's requested size (the StorageClass must allow volume expansion):
status.capacity.storage grows to the new size; CSI drivers such as Ceph RBD expand online (no restart needed).
Unmounting a Virtual Disk
Unmount the data disk from the virtual machine; only virtual machines in the stopped state can unmount disks.
Procedures
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Disk.
-
Click ⋮ > Unmount next to the virtual disk to be unmounted and confirm.
Using the API
Detach the hot-plugged disk:
This issues the removevolume subresource and the disk is detached (the entry leaves VirtualMachineInstance.status.volumeStatus). The KubeVirt API supports detaching from a running virtual machine, but make sure the disk is no longer in use inside the guest (unmounted at the OS level) before removing it, to avoid data loss.
Deleting a Virtual Disk
Deletion is only supported when the virtual disk is in an unmounted state.
Note: System disks cannot be deleted.
Procedures
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Disk.
-
Click ⋮ > Delete next to the virtual disk to be deleted and confirm.
Using the API
The backing PVC is owned by the DataVolume and is garbage-collected with it. If CDI already garbage-collected the DataVolume, delete the PVC directly (kubectl delete pvc datadisk-1 -n demo).
StorageProfile and cross-namespace clone scope
CDI publishes a StorageProfile for each StorageClass that describes how disks can be provisioned and cloned on that backend. Inspect it to see the supported access/volume modes and the clone method:
cloneStrategy (csi-clone, snapshot, or host-assisted copy) determines how a bootable volume or VM clone copies a disk; whether snapshot/clone work at all depends on the StorageClass having these capabilities.
Cross-namespace clone scope: when creating a virtual machine or a bootable volume, the console only offers boot images from the current namespace and kube-public as clone sources. This UI guardrail — not RBAC — is the supported boundary on this platform: publish shared golden images to kube-public, where the built-in os-images.kubevirt.io:view role makes them clone-able by every authenticated user.
CDI's upstream
datavolumes/sourcepermission (thedatavolume-clonerClusterRole) does not reliably gate CSI-path clones, so binding it is not a supported or sufficient way to expose images from an arbitrary non-public namespace. Usekube-publicfor shared images instead.