// Module included in the following assemblies:
//
// * virt/virtual_machines/creating_vms_custom/virt-creating-vms-by-cloning-pvcs.adoc

:_mod-docs-content-type: PROCEDURE
[id="virt-cloning-pvc-to-dv-cli_{context}"]
= Cloning a PVC to a data volume

[role="_abstract"]
You can clone the persistent volume claim (PVC) of an existing virtual machine (VM) disk to a data volume by using the command line.

You create a data volume that references the original source PVC. The lifecycle of the new data volume is independent of the original VM. Deleting the original VM does not affect the new data volume or its associated PVC.

Cloning between different volume modes is supported for host-assisted cloning, such as cloning from a block persistent volume (PV) to a file system PV, as long as the source and target PVs belong to the `kubevirt` content type.

ifndef::openshift-rosa,openshift-dedicated[]
[NOTE]
====
Smart-cloning is faster and more efficient than host-assisted cloning because it uses snapshots to clone PVCs. Smart-cloning is supported by storage providers that support snapshots, such as {rh-storage-first}.

Cloning between different volume modes is not supported for smart-cloning.
====
endif::openshift-rosa,openshift-dedicated[]

.Prerequisites

* You have installed the {oc-first}.
* The VM with the source PVC must be powered down.
* If you clone a PVC to a different namespace, you must have permissions to create resources in the target namespace.
* Additional prerequisites for smart-cloning:
** Your storage provider must support snapshots.
** The source and target PVCs must have the same storage provider and volume mode.
** The value of the `driver` key of the `VolumeSnapshotClass` object must match the value of the `provisioner` key of the `StorageClass` object as shown in the following example:
+
Example `VolumeSnapshotClass` object:
+
[source,yaml]
----
kind: VolumeSnapshotClass
apiVersion: snapshot.storage.k8s.io/v1
driver: openshift-storage.rbd.csi.ceph.com
# ...
----
+
Example `StorageClass` object:
+
[source,yaml]
----
kind: StorageClass
apiVersion: storage.k8s.io/v1
# ...
provisioner: openshift-storage.rbd.csi.ceph.com
----

.Procedure

. Create a `DataVolume` manifest as shown in the following example:
+
[source,yaml]
----
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
  name: <datavolume>
spec:
  source:
    pvc:
      namespace: "<source_namespace>"
      name: "<my_vm_disk>"
  storage: {}
----
+
where:
+
`<datavolume>`:: Specifies the name of the new data volume.
`<source_namespace>`:: Specifies the namespace of the source PVC.
`<my_vm_disk>`:: Specifies the name of the source PVC.

. Create the data volume by running the following command:
+
[source,terminal]
----
$ oc create -f <datavolume>.yaml
----
+
[NOTE]
====
Data volumes prevent a VM from starting before the PVC is prepared. You can create a VM that references the new data volume while the
PVC is being cloned.
====
