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:


libvirtd:x:128:mike

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.

Setting CLI resolution in Ubuntu

Setting the resolution for the console is not much of a concern normally. Your virtual terminals are set to a reasonable resolution by default on a normal Ubuntu desktop installation. If you run Ubuntu server in a virtual machine, however, you are stuck with 640×480 resolution.

Recent versions of Ubuntu all use Grub2 so the way to change the resolution is now:

sudo vi /etc/default/grub

Then add the following:

GRUB_GFXMODE=1024×768
GRUB_GFXPAYLOAD_LINUX=keep

Save the file and run:

sudo update-grub

On your next reboot, there it will be.

Lucid Alpha 3 in Virtualbox.

Everything I am hearing about the upcoming Lucid Lynx release of Ubuntu sounds really great. I just grabbed Alpha 3 from the Ubuntu site and was a little dissappointed to see it hang as soon as I selected “Install Ubuntu”. The fix is to turn off the ACPI option in the system settings for your VM.

The side-effect of this is that the virtual machine will no longer close the window and disappear when you shut it down. C’est la vie.

From there the installer started up fine, but it hung again when I tried to update the installer. When I skipped the update it installed without any other problems. Thats what worked for me on Virtualbox 3.08 OSE.

UPDATE: This issue still seems to be effecting the new Lucid Beta 1…

Connecting to a web server on a VirtualBox guest.

One of the things I did frequently when using VMware is connect from my host (usually Windows) to my guest (usually Linux). The fact that I don’t really remember how I set that up seems to indicate that it was pretty trivial or just worked “out of the box” (which is a funny thing to say about a VM). After happily using Virtualbox for a while now, the need to connect from host to guest has inevitably reared its head and I was a little surprised that there does not seem to be a straight forward way to do that. Turning as one usually does in such a situation, to Google, and since it was a bit of a fiddle I thought I would scrawl it down here.

The Windows version:

Open the Windows command line and navigate to

C:\Program Files\Sun\VirtualBox>

There are three commands that need to be issued. The command is a little daunting at first glance so here are the important parts:

“karmic” is the name I gave my VM when I created it.

“pcnet” refers to the PCNet virtual network card that I am using in my VM which you can select in your network settings. e1000 is also valid if thats what you’re using.

“railsdev” is the name that will be given to the port forwarding configuration that these commands set up.

The rest should be fairly self explanatory:

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/Protocol” TCP

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/GuestPort” 3000

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/HostPort” 3000

On *nix things are roughly the same, except that the default network card is the Intel Pro/1000 instead of the pcnet you can see above. Consequently you will need to do something like this:

vboxmanage setextradata “mavrick_server” “VBoxInternal/Devices/e1000/0/LUN#0/Config/rails/Protocol” TCP
vboxmanage setextradata “mavrick_server” “VBoxInternal/Devices/e1000/0/LUN#0/Config/rails/GuestPort” 80
vboxmanage setextradata “mavrick_server” “VBoxInternal/Devices/e1000/0/LUN#0/Config/rails/HostPort” 8080

You can see that here I am forwarding port 8080 on the host to port 80 on the guest and naming the forwarding configuration “rails”. Also notice the “e1000” that identifies the network card. Other things to note are that the quotes around the VM name (“mavrick_server” in the above example) MUST be there and they must be regular quotes not angled ones like  “ or ”. Angled quotes will be assumed to be part of the machine name and throw an error like this:

ERROR: Could not find a registered machine named ‘“webserver”’

Replace the quotes with proper ones and you should be good.

Happy forwarding!