FreeBSD 10.3 poor disk I/O as KVM guest

I am using KVM on CentOS 6 (host) and FreeBSD 10.3 as a guest system. FreeBSD's hard disk write performance was horrible! It was about 2-5 MB/s! After searching some time, here the fix which led the write speed to 40 MB/s!

Open your VM config file with

# virsh edit <SERVER>

then find your hard disk config line and change the cache and io paramter accordingly. Here the wonderful line which gave it a awesome performance boost:

<disk type='file' device='disk'>
    ...
    <driver name='qemu' type='raw' cache='none' io='native'/>
    ...
</disk>

Save your config file and reboot your FreeBSD guest, you will see the difference is huge (at least in my case)

Change IDE to VirtIO Disk in KVM

I want to show you how to change an IDE disk to a VirtIO disk in an already done guest. In my example it is a FreeBSD 10.3 guest:

First open your guest's /etc/fstab and change:

all /dev/ada0pX to /dev/vtbd0pX (FreeBSD only)
all /dev/sdaX to /dev/vdaX (Linux only)

Now shutdown the guest and connect to your KVM host's shell. Then type:

# virsh edit <SERVER_DOMAIN>

find following line:

<disk type='file' device='disk'>
    ...
    <target dev='hda' bus='ide'/>
    ...
</disk>

and change it to

<target dev='vda' bus='virtio'/>

also remove all occurance of "<address type=…" within the same disk section. On save KVM will regenerate the line for you. Note that this part is needed for correct disk values wihtin the guest!

Now restart your guest and everything should be running.

# virsh start >SERVER_DOMAIN>

PLEASE NOTE: This method has worked for me on any Linux/FreeBSD guest but apparently there were some windows installations were this method broke the MBR, so please do a backup first!