Wednesday, August 29, 2012

How to export virtual machine configurations from QEMU-KVM

When exporting a virtual machine to use in another system or in a new operating system install, it's very helpful export its configurations. Yesterday I put to work two virtual machines from an old install of my box and I had one problem that caused me a headache: in their new profiles, both virtual machines received a new MAC address. This is obvious... but to discover that this was the problem I spent some time looking the configurations of both virtual machines. To solve this problem in the virtual machine that runs a Linux server, I commented the lines in /etc/udev/rules.d/70-persistent-net.rules because udev wasn't recognizing the MAC address of eth0 as configured in /etc/sysconfig/network-scripts/ifcfg-eth0 and it created a new ethernet device - eth1 - with the new MAC address (the one from the new profile). Then I updated /etc/sysconfig/network-scripts/ifcfg-eth0 with the new MAC address and rebooted the virtual machine. These three steps were sufficient.

But... how to export the configurations to a file to import them in another system or install? All the commands below need to be executed as root or with sudo.

[root@rafael vms]# virsh --connect qemu:///system dumpxml VM_NAME > VM_NAME.xml

If you don't know the name of the virtual machine you want, you can retrieve it with the virsh --connect qemu:///system list --all command.

Now you have the configurations file in XML format. To import and apply the configurations file to a virtual machine, use the virsh --connect qemu:///system define FILENAME.xml command.

No comments:

Post a Comment