In an earlier post we looked at how to install KVM virtualization on Ubuntu Linux. Now we are going to learn how to change parameters of an existing virtual machine.
Configuration of KVM virtual machine (VM) is stored as a usual xml file. By default it is located in /etc/libvirt/qemu directory.
I assume you have already installed KVM and created one or several virtual machines, so the configuration files already exist.
Type this command:
ls -l /etc/libvirt/qemu
The command will result in output like this:
total 16 drwxr-xr-x 3 root root 4096 2011-01-25 06:00 networks -rw------- 1 root root 2011 2011-02-02 18:00 testVM.xml
networks directory contains a network bridge configuration file. testVM.xml is a configuration file of testVM virtual machine. Type this:
sudo cat /etc/libvirt/qemu/testVM.xml
(of course, use a name of a virtual machine which exists on your computer instead of testVM.xml).
This will print the configuration file. Here is an example:
<domain type='kvm'>
<name>testVM</name>
<uuid>bf39f3d2-8c59-d9f2-d573-45bba7486a9f</uuid>
<memory>524288</memory>
<currentMemory>524288</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc-0.12'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/testVM.img'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='network'>
<mac address='52:54:00:47:d3:96'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</memballoon>
</devices>
</domain>
The file is pretty self-explanatory. For example the xml snippet below defines a size of RAM allocated to the virtual machine:
<memory>524288</memory> <currentMemory>524288</currentMemory>
Please note, the memory is allocated in kilobytes, so the number above corresponds to 512MB (524288 = 512 * 1024).
The xml snippet instructs VM to use one CPU core:
<vcpu>1</vcpu>
Another xml snippet defines that VM uses file /var/lib/libvirt/images/testVM.img as a hard drive:
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/testVM.img'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
Of course, it is possible to edit the file in place. But this is rather a risky method since we can make a mistake etc. The recommended method includes 3 steps. First export the VM xml file via virsh, then edit it and finally import back.
To export VM configuration file we have to type:
virsh dumpxml testVM > /tmp/testVM.xml
Please note, we must put only a name of the VM after dumpxml parameter, without a path or an extension.
Now we can edit the exported xml. Let’s make a mistake in it for a purpose so that to see how an import procedure is going to handle this later. Let’s suppose we changed the snippet which defines a number of CPU to something like this:
<vcpu>XYZ</vcpu>
Now type:
virsh define /tmp/testVM.xml
Let’s verify that the testVM.xml file has been updated indeed. Type:
ls -l /etc/libvirt/qemu
Notice, file timestamp has been updated and now reflects the time when we imported the file.
How about the wrong number of CPU? Type:
sudo cat /etc/libvirt/qemu/testVM.xml | grep vcpu
You should see this:
<vcpu>1</vcpu>
which means that virsh silently corrected our mistake.
Hi,
Thank you for the info. In case the image is on a remote server? Using ssh, what would be the domain.xml file.
Thank you.
I’m not 100% sure I understand your question. The XML file defines a configuration of VM and as a file it may be stored anywhere. However virtualization tools look for such files in a particular local directory. If your question is how to make them looking for such files somewhere else over ssh, I’m not sure if this could be done. The directory must be on a filesystem mounted on the server/computer as far as I know.
Hi,
I want to load a new image “testVm1.img” which i exported from a different vm to my vm.
Can i change the source file of the VM to the exported image file path?
is that the way i do it or is there a better way to do it?
Thank you.
Gui for KVM – http://www.webvirtmgr.net
I am Ramsingh
[...] How to change configuration of KVM virtual machine « Vlad Nevzorov’s blog – November 29th ( tags: kvm virtualization change configuration dumpxml virsh howto guide tutorial reconfigure ) [...]