KVM in this case is the linux ‘Kernel-based Virtual Machine’, not Keyboard/Video/Mouse. I’ve always been puzzled why you would name the new whiz bang virtualization technology for linux the same as a rather mundane piece of equipment found in most data centres.
So I’ve been a big virtual machine user for many years. Mainly using the desktop products like Vmware Workstation (and Fusion on the Mac) and I’ve tried Virtualbox a few times. I tried VMware Server a few times but was never happy with its performance on linux. But, Vmware ESX is always quite impressive. Being so low level it obviously has quite a few extra ‘smarts’ over the desktop and ‘on top of a regular OS’ type VM products. It is incredibly popular in data centers, and has the key benefit of ‘being around for years’, and has consequently been refined and refined.
So that brings me to KVM. In theory it should be the linux world alternative to ESX. Sure Xen kind of does the same thing, but KVM is very integrated into the kernel supposedly, whereas Xen has its own microkernel or somesuch. Of course, when KVM first came out, I tried it and it didn’t seem to work very well, so I forgot about it until now. Lately, I’ve been looking at other distros and have been playing quite a bit with Ubuntu 9.04. Usually I would hate something like Ubuntu due to the volume of updates you typically get, but I was interested in ext4 performance and I had also read that KVM was reasonably integrated into it, so it seemed like an easier way to try those things out.
So I installed Ubuntu 9.04 (the 32 bit version initially) on my 2Gb ram core2duo on top of ext4 and read this KVM post at Adoleo to get some hints on setting it up. I must admit there is a lot of ‘not quite’ consistent information on the net about setting up KVM … and I can understand people who have tried setting it up, got stuck, googled for answer … and then given up. The Adoleo post is quite good as it’s quite recent. There were a couple of extra apt-get’s I needed to do to get everything going (you need the qemu package for example).
Now, with all the bits installed, I of course wanted to install a guest. This is where I think a lot of info on the net becomes confusing. It’s very much a case of heaps and heaps of ‘abstractions’. Here’s how I think everything fits together;
- kvm itself is a low level kernel module that does the virtualization stuff using the Intel VT extension or the AMD SVM extension
- qemu is a software i386 (and others) CPU emulation system that has been around for years and has a lot of tools necessary for doing virtualisation stuff. In the past qemu has been slow.
- qemu now can leverage itself against kvm to do ‘in hardware’ virtualisation. So I think if you run the kvm command (which seems ot take all the same args as the qemu command) on a VT or SVM capable CPU and you just happen to be emulating a intel type PC architecture system then it’ll go and use the dandy fast hardware virtualization stuff.
- Launching these virtual machines using the kvm command at the command line means you end up with a long list of args. Someone must have thought ‘Lets come up with some clever XML abstracted network thingee instead’ and hence you have this libvirt API which seems to be an API for managing virtual machines both locally and across a network. All the args to the kvm command are now in the form of some XML file.
- Someone thought we need some GUI management tool just like vmware etc have and you end up with virt-manager which seems to be used in the majority of examples on the net. virt-manager uses the libvirt API.
Well, all the above is how I think it works … today 😉
So based on that Adoleo info for the basic low level setup, I think I started up virt-manager (you might have to apt-get it too) and you get a window that says;
Of course I could not find a howto anywhere that mentioned why there are two entries and what each one is for. What I think they mean is that localhost (System) is for all the virtual machines running as root level , and the localhost (User) is for all the machines running as your username (???). Anyway I clicked the User one and ‘connected’ to it OK, then right clicked to create a new VM. I think I tried a ubuntu 9.04 VM first. That sort of worked OK. You get a dandy graphical console view and even though the mouse was sometimes erratic (there is a hint somewhere to configure the virtual mouse as a usb tablet to get around this) I got the VM installed OK.
Then of course I could not get networking to go. I’ve set up bridging using brctl before so I had an idea in my head how I wanted things to work. I changed my /etc/network/interfaces to bridge my eth0 into a br0 bridge (as per that Adoleo page), and my host side networking worked fine. Guest networking was a no go. it eventually clicked that even though my user had write permission to /dev/net/tun that it probably was not creating the tap devices in the first place etc. I googled for a while, gave up, then thought “I’ll just make the VM’s part of that localhost (system) thing which should run as root and get rid of my network probs.
This meant working out where the libvirt XML config files live for the VMs. They live in ~/.libvirt/qemu. Just mv them from there into /etc/libvirt/qemu, and restart the libvirt daemon (I seem to have to do this restart a lot);
Probably shutdown all your VMs too and stop virt-manager and start it again and you should now see all your VMs under ‘localhost (System)’.
Now my networking worked. I had something like this in my XML file for the ubuntu VM;
and also I had the following somewhere for the mouse;
<input type=’tablet’ bus=’usb’/>
So now I tried a Windows XP VM. It also worked. I had some fun with the networking. Initially I used a line like the ones above, which specify that virtio thing. Virtio is some special driver interface that KVM virtual machines can use to get much faster disk and network performance. It requires a special driver in the guest OS. I think in the case of ubuntu 9.04 this is already integrated. With my XP VM I would just get a ‘Ethernet Controller’ device detected … and for the life of me I could not track down where the Windows XP virtio drivers now live on the net. All the links to them on the net seem either broken or really old. So I kind of gave up, and my XP VM now just has a network section like so (without the virtio ref);
In the XP device manager I now just see a Realtek 8139C network device. It is autodetected and configured and networking just works.
So then I tried a Windows 7 RC VM. The only ISO I have is for the 64 bit version. Of course, one of the limitations of KVM is that you cannot run a 64 bit guest on top of a 32 bit OS (I think some of the vmware products can do this). Anyway, my host OS install was relatively new (and destroyable) so I downloaded the 64 bit iso of Ubuntu 9.04 desktop and got that up and running. And set everything up AGAIN. Now I tried the Windows 7 install and suffice to say it does not work. It starts, it goes a bit of the way through the install and then dies. So far I’ve googled but haven’t found a solution.
One very noticeable thing is that the VMs seem quite snappy and responsive. A lot more so than any of the other virtualization products I’ve tried on this server. And I get the impression that people are starting to use KVM for production workloads. Sure I was disappointed that I couldn’t get Windows 7 to run, but thats not a big deal for me. I found the virt-manager was good at the basic ‘wizard to create a simple VM’, but some of the finer points about how it works have a way to go.