Making Virtual Machines with KVM and Virt-manager

I have used virtual machines for a quite a while now and have drifted back and forth between VMware and Virtualbox. While my initial experience of Virtualbox was good, between the acquisition by Oracle, the TAINT_CRAP thing and generally finding it slow and sometimes overly complicated, I thought I would explore some other options. Having recently discovered my laptop supports hardware virtualization, I thought I would try out KVM.

KVM stands for Kernel-based Virtual Machine and Ubuntu’s documentation sums up the expected uses nicely; “Ubuntu uses KVM as the back-end virtualization technology primarily for non-graphic servers”. So while this is definitely created with servers in mind, I figure I will explore using it as a Virtualbox replacement and see how that goes.

So after enabling virtualization in my BIOS I installed all the packages:

sudo apt-get install virt-manager qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

The first thing I learned after starting virt-manager is that KVM is using QEMU as its processor emulator. This becomes obvious when you launch virt-manager and notice that it can’t connect to QEMU on localhost.
To get that working just add yourself to the libvirtd group. I did it manual style:

sudo vim /etc/group

and add yourself to the group like so:


After that you will need to logout and log back in (restarting works too) and you should see localhost(QEMU) in the virt-manager GUI indicating that a connection has been made.

The process of setting up a virtual machine is similar to what you would find in VMWare or Virtualbox. Just click the “Create new virtual machine” button and its pretty self explanatory. One thing that stood out as a little concerning is an little red error icon when setting up the network config.

If you mouse over it, it says “could not initialize HAL for interface listing”. HAL of course has been deprecated and removed from Ubuntu (and replaced by Udev) so its not a surprise that it can’t be found. I wasn’t sure what to make of this but it turns out not to be an issue; the VM boots up happily and is able to sort out a network connection just fine.

HAL error in virt-manager
I am curious to see what it will be like to work with this for a while. Particularly doing things like using the VM as a server of various kinds which is terribly clunky in with Virtualbox. Well I still have lots of tinkering to do but this is enough to get the experiment underway.

Ditch VMware. Don’t look back.

After working in Ubuntu running in VMware for my Ruby on Rails development over the last few months I have come to the realization that VMware is really annoying.

First, I am tired of playing Russian roulette with their poorly chosen keyboard shortcuts. I have inadvertently rebooted the whole VM with a Control+R intended for the Firefox inside the VM more times than I care to admit. Much wailing and gnashing of teeth followed.

Equally poorly planned, but less damaging is their co-opting of the standard undo shortcut Control+Z. The fine folks at VMware decided to use that to suspend the VM which you will eventually discover after flipping between the VM and the host OS and then trying to undo something…

While the fact that switching between the guest and the host OS a few times makes their network connection crash and their seeming inability to make their shared folders work with Ubuntu in any sane way (hopefully fixed now…), both rank on my list of frustrations, the worst by far is the mouse.

I was hoping to get the mouse working better once the VMware tools were installed but that never ended up being the case. For whatever reason after the install I still had to explicitly click in the VM to get it to grab the mouse (or press Control+G… Don’t get me started…) and Control+ALT to release it. I suppose I might have been able to figure out some sort of fix for that had it really caused some acute aggravation, but for the most part it remained as a low level annoyance.

The acute aggravation came from the fact that VMware assumes that anytime you move your mouse anywhere near the top of the screen that you would like to jump out of the VM and access their menu.

Without fail this completely screws up the mouse and I have to try to click several times inside the VM to convince it to grab the mouse again.

Well I am pleased to tell you there is a fix for all of that. Virtualbox. No stupid shortcuts, is actually capable of running compiz-fusion, shared folders that actually work (sudo mount -t vboxsf sharename /mnt/share is all thats needed after you set up your share, exactly what a *nix user would expect), and a single key (the control button on the right side of the keyboard) that releases you from the VM. As a bonus it even seems faster than VMware. The best part is that you don’t have to go trawling on piratebay to get a copy, since it is open source and freely available from their website.

Ditch VMware. Don’t look back.

VMware tools and shared folders in Unbuntu 9.04 Jaunty

The latest version of Ubuntu does indeed have some sexy new features, new notifications, eucalyptus cloud support. All around a pretty awesome release. In what I will kindly call a fit of nievete, I decided to upgrade the my VM that I have been using for web development. Although the upgrade from 8.10 to 9.04 went smoothly, the reinstall of VMware tools failed leaving me without any shared folders. So after a little profanity and a lot of googling I thought I would share what got my shared folders back up and running.

First you will want to make sure that you have the headers and other stuff so VMware tools has what it needs to compile everything:

sudo apt-get install linux-headers-`uname -r` build-essential

If you are not running VMware 6.5.2 you will likely be asked where your header files are. 6.5.2 added “experimental” support for Jaunty so it already knows where to look. I was running the server version so my headers were in/lib/modules/2.6.28-11-server/build/include.

If you are running the desktop version you can probably find them here: /lib/modules/2.6.28-11/build/include

What is the location of the directory of C header files that match your running
kernel? [/lib/modules/2.6.28-11-server/build/include]

The first time I tried to install VMware tools, two of the modules failed. I upgraded to version 6.5.2 build 156735 and tried it again and that time only the HGFS module failed with the following error:

CC [M]  /tmp/vmware-config3/vmhgfs-only/page.o
/tmp/vmware-config3/vmhgfs-only/page.c: In function âHgfsDoWriteBeginâ:
/tmp/vmware-config3/vmhgfs-only/page.c:763: warning: ISO C90 forbids mixed declarations and code
/tmp/vmware-config3/vmhgfs-only/page.c: In function âHgfsWriteBeginâ:
/tmp/vmware-config3/vmhgfs-only/page.c:867: error: implicit declaration of function â__grab_cache_pageâ
/tmp/vmware-config3/vmhgfs-only/page.c:867: warning: assignment makes pointer from integer without a cast
make[2]: *** [/tmp/vmware-config3/vmhgfs-only/page.o] Error 1
make[1]: *** [_module_/tmp/vmware-config3/vmhgfs-only] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.28-11-server’
make: *** [vmhgfs.ko] Error 2
make: Leaving directory `/tmp/vmware-config3/vmhgfs-only’
Unable to build the vmhgfs module.

Fortunately some googling turned up this clever fellow who tells you how to fix the problematic line of code. I did it and am happy to report that it works. Just to make everybody’s lives a little easier I thought I would make the patched code available to save people some time and bother.  You can see the link to it in the code below. So without further ado, here is what you need to do to fix the HGFS. You will need the vmware-tools-distrib folder. I had it laying around from my previous install attempts.

mike@ubuntu:~$ cd vmware-tools-distrib/lib/modules/source/

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ rm vmhgfs.tar
rm: remove write-protected regular file `vmhgfs.tar’? y

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ wget
–2009-05-03 00:18:25–
Connecting to||:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 901120 (880K) [application/x-tar]
Saving to: `vmhgfs.tar’

100%[======================================>] 901,120      176K/s   in 5.8s

2009-05-03 00:18:32 (152 KB/s) – `vmhgfs.tar’ saved [901120/901120]

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ ls -al vmhgfs.tar
-rw-r–r– 1 mike mike 901120 2009-05-02 23:26 vmhgfs.tar

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ chmod 444 vmhgfs.tar

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ ls -al vmhgfs.tar
-r–r–r– 1 mike mike 901120 2009-05-02 23:26 vmhgfs.tar

Now that the permissions are set correctly just rerun the install script:

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ sudo ./

I hope that ends up being useful for somebody.