Exporting libvirt+KVM virtual machines to files
I am going to retire an old libvirt + KVM server, but I need to preserve the VMs. Unfortunately, the network is down and I cannot create connections to the system.
Is there any way to export the VMs using virsh
or any other utility?
Clarification: I need disks and everything. I will deploy machines to another server.
Solution 1:
If you need to backup your vm configuration using virsh you can use the following command
virsh dumpxml vmname > vmname.xml
If you need to move your vm to other server, you can dump your vm config and transfer the xml, if you are using files as backend storage for your vm you can copy the files to other server using scp or rsync, when you copied the disk files of the vm, you can try to start the vm with virsh define /tmp/myvm.xml && virsh start myvm
Solution 2:
You should be able to image your disks from a snapshot:
First you wil need to make sure the Vm is not running:
virsh suspend vm
Now you can create a snapshot make sure to adjust the size 100M and the name vm-root-snapshot to your own needs.
lvcreate -L 100M -n vm-root-snapshot -s /dev/sysvg/vm-root
After this you can start the VM again.
virsh resume vm
Now that you have the snapshot you can create the image and delete the snapshot:
dd if=/dev/mapper/sysvg-vm--root--snapshot of=/tmp/vm-root.img bs=1M
lvremove /dev/mapper/sysvg-vm--root--snapshot
The image can be copied to the new server and imported to the LVM on the new server with dd
dd if=/tmp/vm-root.img of=/dev/mapper/sysvg-vm--root bs=1M
Also don't forget to import your XML file.
virsh define /path/to/vm.xml