Data volumes enable OpenShift to dynamically create the PVCs that represent the used disks in a VM. The VM disks can be imported from a URL or cloned from an existing PVC. You can attach several data volume resources to a VM. Inside the VM, each data volume shows as a disk that you can partition, format, and then mount by using the operating system tools. The disk type inside the VM depends on the selected interface when you attach the data volume:
The disk shows as a standard SCSI device that most operating systems recognize.
Linux systems name these disks in the /dev/sd format.X
The operating system uses a VirtIO driver that communicates with the virtualization layer for optimal performance.
Some operating systems do not provide that driver by default.
Linux systems include the driver and name these disks in the /dev/vd format.X
Use the OpenShift web console to create a data volume and attach it to a VM as an additional disk. Navigate to → , select the VM, and then navigate to → . Click and then complete the form.
![]() |
When you hot plug a disk to a running VM, SCSI is the only available interface. To use the optimized VirtIO interface, stop the VM before attaching the new disk.
The source section of a data volume resource provides the details of the disk image to inject into the PV. The following screen capture shows that you can select the source from the window when using the OpenShift web console.
![]() |
The new PVC provides an unformatted raw device. You can use your operating system tools to partition and then format the new block device from inside the VM.
OpenShift Virtualization copies the PVC that you provide and then uses that copy as the VM disk. Because the source PVC must not be in use for the cloning process to start, you must stop any pods or VMs that are actively using it.
OpenShift Virtualization downloads the container image from a container registry and uses the disk in that container image as the VM disk. This source option is similar to the registry option, except that OpenShift Virtualization does not create a data volume, PVC, or PV resources, and therefore does not consume space on your back-end storage.
You can mount the disk read/write to the VM, but the data that you write is not persistent. Whenever you restart the VM, OpenShift Virtualization discards your data and restores the disk image to its initial state.
You can use ephemeral storage when you do not need to preserve data, such as temporary files.
Specify the project and name of a data source resource. The data source contains the reference of the original PVC that is imported to a new PVC.
Red Hat OpenShift Virtualization downloads the virtual disk image from the URL that you provide and then extracts it to the new volume.
The virtual disk image must be in the raw format or in the QEMU copy on write version 2 (qcow2) format.
The disk usually includes file systems that you can mount to access their data from inside the VM.
Because the disk is read/write, Red Hat OpenShift Virtualization preserves all your changes across VM restarts.
OpenShift Virtualization attaches the PVC that you provide as a disk. That PVC might come from a data volume that you detached from another VM and that you want to reuse with your VM.
Do not use a PVC that is currently attached to another VM.
Even though Red Hat OpenShift allows pods and VMs to concurrently access volumes in ReadWriteMany access mode, the file systems on these volumes might not support that mode.
The ext4 or XFS file systems, for example, do not support concurrent mounting from multiple systems.
Doing so can result in file system corruption or inconsistencies when attempting to read data.
OpenShift Virtualization downloads the container image from a container registry.
The container image contains a disk image in the raw or qcow2 format in the /disk/ directory.
OpenShift Virtualization extracts that disk image and copies it to the volume.
This source option is similar to importing disks from URLs, and is useful when a container registry is already deployed in your organization. Instead of installing a new file server to distribute your disk images, you can store these images in your container registry.
Because container registries can manage only images, you must store your disk images in container images in the /disk/ directory.
These images are not meant to be run as containers, and they usually contain only the /disk/ directory and the disk image.
You can upload an existing qcow2 disk image to the cluster and use it in a VM.
The selected image is uploaded and imported to a PVC that is attached to the VM.
You can create the disk image with tools such as qemu-img or virt-make-fs.
You can detach disks only from stopped VMs. After you stop the VM, navigate to → , click the vertical ellipsis icon to the right of the disk to detach, and then click . When a confirmation message appears, click to confirm.
The data is preserved after the disk is detached from a VM. To delete the PVC that contains the disk data, navigate to → , and select the project where the VM is located. Locate the PVC with the VM name followed by the disk name, and then click the vertical ellipsis icon at the end of the row. Finally click .
A confirmation message indicates that the associated data volume is deleted with the PVC. Click to proceed.
You can also delete the data volume resource by using the following command. The underlying persistent volume claim and persistent volume are removed when you delete the data volume.
[user@host ~]$ oc delete datavolume/mariadb-server-my-disk
datavolume.cdi.kubevirt.io "mariadb-server-my-disk" deletedAfter you detach a disk from a VM, you can attach it to a different VM. You can also reattach the disk to the same VM, if needed.
To attach the disk, stop the VM, and navigate to → . Click and then complete the form:
![]() |
Attach an existing PVC to a VM
Select for the source. | |
Select the PVC to attach to the VM. OpenShift Virtualization constructs the name of the PVCs from the name of the initial machine for which you created the disk and from the name that you gave to the disk. |
Do not use a PVC that is currently attached to another VM. Doing so can result in file system corruption or inconsistencies when attempting to read data.
When OpenShift Virtualization copies a disk image to a PV, it allocates only the space that the image uses.
For example, when you create a 10 GiB blank disk, OpenShift Virtualization does not reserve that space with the back-end storage. Instead, OpenShift Virtualization progressively allocates the space when you start writing data to the disk. This mechanism improves usage of your back-end storage, because it consumes only the space that you use.
However, write speed is often reduced, because the system must allocate the disk blocks before allowing the write operations to proceed.
To preallocate the whole disk space, select the checkbox when adding a disk to a VM.
In a data volume resource file, use the preallocation parameter:
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
name: datadisk
spec:
preallocation: true
storage:
resources:
requests:
storage: 10Gi
storageClassName: ocs-external-storagecluster-ceph-rbd-virtualization
source:
blank: {}With this option enabled, OpenShift Virtualization reserves the entire requested space with the back-end storage. This operation consists of writing zeros to the device's blocks for some back-end storage.
OpenShift Virtualization always reports the disk size that you request, even if you do not enable preallocation.
RHOCP enables resizing of PVCs. When you change the size of a PVC, RHOCP automatically resizes the associated PV. Because most VM disks are based on PVCs, you resize a disk by resizing its PVC.
You can only expand PVCs, not shrink them.
Each storage class has a field that specifies whether volume expansion is supported.
When volume expansion is available, the storage class resource allowVolumeExpansion field is set to true.
[user@host ~]$oc get storageclass \ ocs-external-storagecluster-ceph-rbd-virtualization -o yaml | \ grep allowVolumeExpansionallowVolumeExpansion:true
The storage class does not support volume expansion if the allowVolumeExpansion field is absent or is not set to true.
[user@host ~]$oc get storageclass nfs-storage -o yaml | \ grep allowVolumeExpansion
The output of this command is empty because the |
You can navigate to → , select the name of the storage class, and click to inspect the YAML definition and verify whether the storage class supports volume expansion.
To expand a PVC by using the OpenShift web console, navigate to → , select the PVC to edit, click → , type the new size, and click to confirm.
![]() |
You can expand a PVC by editing its resource file and modifying the spec.resources.requests.storage parameter.
[user@host ~]$oc edit pvc/mariadb-server-my-disk-rbdapiVersion: v1 kind: PersistentVolumeClaim metadata: name: mariadb-server-my-disk-rbd namespace: storage-multiple ...output omitted... spec: accessModes: - ReadWriteMany ...output omitted... resources: requests:storage: 8GistorageClassName: ocs-external-storagecluster-ceph-rbd-virtualization volumeMode: Block volumeName: pvc-c87ee674-4ddc-3efe-a74e-dfe25da5d7b3 ...output omitted...
Resizing a PVC does not require stopping the VM that is using it. However, the VM detects the new disk size only after a restart.
Most operating systems report the new size but do not automatically expand the partitions and the file systems.
On Linux systems that enable the cloud-init service, these operations might automatically happen during boot.
For more information about resizing volumes, refer to the Expanding Persistent Volumes chapter in the Red Hat OpenShift Container Platform Storage guide at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/storage/index#expanding-persistent-volumes