On one of our host machine, we get around 70MB/second disk write speed, but KVM guest machine was giving us around 18MB/s write performance.
At that point we came to know about virtio driver. Here is guide to enable virtio
Backup VM config
virsh dumpxml <vmname> > ~/vmname.xml
Replace vmname
with Virtual Machine (Domain) name. You can find correct name by running virsh list --all
Edit VM Config
Run following command to open editor.
virsh edit <vmname>
Find lines like below:
<disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/var/lib/libvirt/images/ubuntu-kvm/tmpU2z98r.qcow2'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' unit='0'/> </disk>
Make following changes:
- Replace
hda
withvda
ANDide
withvirtio
- Remove following line:
<address type='drive' controller='0' bus='0' unit='0'/>
- Add
cache='none' io='native'
option todriver
.
Your update config will look like below:
<disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none' io='native'/> <source file='/var/lib/libvirt/images/ubuntu-kvm/tmpU2z98r.qcow2'/> <target dev='vda' bus='virtio'/> </disk>
Save your changes and exit editor.
Changes to Guest VM’s filesystem
I am not sure if this step is necessary but one tutorial mentions this. I did not try outcome without this step as VM’s I was playing with has some critical data.
Anyway, login to Guest VM’s shell and open in editor vim /etc/fstab
Fine lines like /dev/sdX
. Replace 's'
with 'v'
.
So /dev/sda1
will become /dev/vda1
and /dev/sda2
will become /dev/vda2
and so on.
For changes to reflect
Shutdown Guest VM for its shell. You can use command shutdown 0
Next, from Host machine, run following commands:
virsh destroy <vmname> virsh start <vmname>
virsh reboot won’t work.
At this point you can run your disk I/O benchmarks again to check speed.
In our case performance shoot-up from 18MB/s to 40.8 MB/s.
Hi
Am using KVM in linux. My guest is windows 7. I had a problem windows 7, so i deleted it and left the virtio disk Windows7-KVM.qcow2 untouched.
After that i build one more vm “Virtual_Client_for_Linux_Windows_7-KVM”, whose virtio disk is Virtual_Client_for_Linux_Windows_7-KVM.qcow2.
Now added the “Windows7-KVM.qcow2” to my new virtual machine through virt-manager, but once virtual machine boots up, am not able to see the newly added “Windows7-KVM-qcow2”.
Below is the xml configuration of new vritual machine “Virtual_Client_for_Linux_Windows_7-KVM” for two disk:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='writeback'/>
<source file='/var/lib/libvirt/images/Virtual_Client_for_Linux_Windows_7-KVM.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='writeback'/>
<source file='/var/lib/libvirt/images/Windows7-KVM.qcow2'/>
<target dev='vdb' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</disk>
Could you let me know, why its not detecting new disk.
Sorry. I won’t be able to help with this as I haven’t used Windows in long time.