Monday, 30 June 2014

Convert Virtual Box Windows Client to use virtio drivers

One thing that can make a big performance difference when running Windows under Virtual Box is to use the native drivers for the virtio host system. I saw a big difference, but that was told to me by a friend so I have no numbers to back it up!

By default, certainly on my install, Windows uses an IDE disk and Realtek network cards, but these are just adding a fake layer between the host and the Windows client for no good reason that I could see. By using the Red Hat virtio drivers, you are able to talk directly to the host hardware. There are some tricks however that you need to know in order to make this as painless as possible.

WARNING: You really should backup your client before doing this unless you are happy to risk losing everything. None of the problems I had would have deleted the disk contents but are you really prepared if it did?

ANOTHER WARNING: You will need local access to your virtual machine, remote desktop will not always work when changing network cards and IP addresses etc. Of course you can remote desktop to your host, just not the client.

1) Download the iso with all the libvirt drivers on it from here. This is an ios file that needs to be visible by your virtual machine host. Note, you may need to change permissions on the download and you might need to exit and reopen the host interface in order for it to re-cache the files in the relevant location.
2) Mount the iso image onto the cdrom drive of your windows client and then open a command prompt and navigate into the correct cd folder for your build e.g. d:\win7\amd64. You can then use pnputil.exe to add inf packages into the Windows driver cache, which makes installing them quicker and easier. The snytax is pnputil.exe -a filename.inf. Running that will show a security warning but otherwise should show that it is added. I did this for all the inf files in the folder (about 6).
3) Reboot your client and ensure that any automatic driver updates are applied during the reboot. There might not be any, but it should just make sure!
4) Once the reboot has completed, you can now shutdown your client. Do not reboot it, it needs to be shutdown to change the hardware settings.
5) Once shutdown, it is up to you whether you want to do the network cards and hard disk drive at the same time. I would recommend doing them one at a time just to keep problems to a minimum but it is up to you. Read down if you also want to do the disks but for now, we will continue with the setup for the network cards.
6) Open the client settings on the shutdown client and change the network card type from "Default" to "virtio". This is all you need to do before restarting but note that depending on your IP address settings, you might now have lost your original IP address temporarily (Windows will see this as a card change), if you are running DHCP then you probably won't care.
7) Start up the client and check in Device Manager that your network card now shows as "Red Hat virtio" or similar, rather than "Realtek...". Make any changes you need into your network properties such as resetting the IP address to a static value (Note that Windows will ask you if you really want to reassign the old IP address to the new card). You can now shutdown to do the disks.
8) You cannot change the disk type directly because the plug-n-play driver install can only take place after Windows has started booting. To get around this, we create a second disk (of any size, say 1Gb?), set it to virtio and start the client again to install the drivers for the second disk. This takes a little while but if you installed the packages properly earlier from the drivers CD, this should all work automatically and Windows will start up after it is finished. You can check the second disk has worked by starting disk management but it won't appear in Explorer since it is un-initialised and un-formatted.
9) Shutdown the client again, this time you need to change the main disk from IDE to virtio, REMOVE the second disk you just added and restart. It is important to remove the second disk otherwise the client will attempt to boot from it and fail (in my case, the numbering orders the hard disks!). Because the virtio drivers are now installed into Windows for the second disk, it should have no problem booting from the first disk with the same drivers.
10) All things having worked, you should be able to boot up as before and again, check Device Manager to ensure the Disk Drive is now using a Red Hat virtio driver rather than whatever was there before (qemu ide driver?)

If your booting to virtio disk fails for some reason, you should be able to kill off the client, set it back to IDE and be up and running again to find out what you did wrong.

If you end up in an endless network boot cycle and windows won't start, check the hard disk order in your settings and ensure your proper disk is the first one, if it isn't, I think you have to change the boot order in the client bios, I can't see how to do it in the settings.
Post a Comment