Copying the Virtual Drive and Configuration File
This section describes how to copy a VM, involving virtual drive copy and configuration file modification.
- Check the location of the virtual drive to be copied.
virsh dumpxml vm0 | grep "source file"

- Copy the virtual drive. Ensure that the drive space for storing the new virtual drive is sufficient.
cd Custom path to the new virtual drive cp /var/lib/libvirt/images/vm0.qcow2 vm1.qcow2
- Copy the VM configuration file.
virsh dumpxml vm0 > vm1.xml
- Modify the configuration file.
- Open the configuration file.
vim vm1.xml
- Press i to enter the insert mode. Change the values of name, uuid, and mac to ensure that the name, UUID, and MAC address of each VM is unique. In addition, change the value of source to the path configured in 2.
<name>vm1</name> <uuid>dfbd8ad1-34ef-423d-8b9c-f7551654b09f</uuid>

<mac address='52:54:00:be:e7:69' />
<source file=' /Drive image directory/vm1.qcow2' index='2' />
- Press Esc to exit the insert mode. Type :wq! and press Enter to save the file and exit.
- Open the configuration file.
- Create a VM.
virsh define vm1.xml

- Check whether the VM is created.
virsh list --all
- Obtain the GPU nodes corresponding to the NUMA node bound to the VM based on Querying PCIe Node Information of a GPU.
- Log in to the VM and remove current GPU nodes.
virt-manager


- Obtain the PCIe nodes of the GPUs matching the current VM by following instructions in Querying PCIe Node Information of a GPU. Then choose Add Hardware > PCI Host Device, select nodes, and click Finish to add the matching PCIe nodes.

- If SR-IOV is enabled for the VM, delete the original SR-IOV vNIC.

Add a new SR-IOV vNIC by referring to Configuring the Host Network.

- If drive partition passthrough is enabled for the VM, delete the original passthrough drive partition.

Add a new drive partition by referring to 15.

Parent topic: VM Copying