18

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.

2
  • virsh dumpxml vmname > vmname.xml
    – c4f4t0r
    Jul 22, 2015 at 6:44
  • Will take a look, thanks. Why not submitting as an answer? However, I need the export with disks and everything.
    – bayindirh
    Jul 22, 2015 at 6:50

4 Answers 4

25

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

0
6

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
2
  • Why did you use the way with lvm? Why not stop the machine, copy the image and let it run. What I see is you stop the machine, copy it into lvm and then make the new iso out of it. What's behind it?
    – Cutton Eye
    Sep 30, 2019 at 7:37
  • @CuttonEye technically the lvm step is unnecessary. However for a VM with large disks it can save on the downtime if you just want a once-off backup of the VM or if you are duplicating the server for use elsewhere.
    – zaTricky
    Oct 2, 2022 at 0:36
4

Besides virsh dumpxml which will export the VM settings into a XML file:

Copy the VM disk image(s), if they are sparse or on a block volume, the correct way is using qemu-img convert -O output_format source destination

To import, edit the XML to reflect the new location of disk images, and then run virsh define path/to/dumpXML

0

You can find your VM config files (exported by virsh dumpxml vmname > vmconfig.xml) and also qemu network config, inside '/etc/libvirt/qemu' folder. Than manually copy the vm config file to the same libvirt '/etc/libvirt/qemu' from your new libvirt install folder.

If necessary, you could also backup/compare all libvirt *.conf config files to compare all config from previous install. They are inside '/etc/libvirt'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.