The command line

GNU/Linux, web development and some other things

Goodbye VirtualBox, Welcome KVM/virt-manager

In fact I don’t have anything against VirtualBox, either the full version or the OSE version. What is more, it is a wonderful piece of software and it never gave me any serious problem. The interface it is one of the most friendly and easy to use that I have found.
In spite of that, I felt that VirtualBox was more focused to the user having a couple of virtual machines running for short periods of time (note: It never had a problem when I let it run several days continuously) than aimed to the datacenter where there are dozens of vms running uninterrupted.
On the other side, when I wanted to have a 64bit guest (in times of VirtualBox 1.5, version 2 supports 64 bit guests and hardware virtualization without problem) it didn’t have support for it. So, searching I found KVM and, in principle at least, it had the same functionality than VirtualBox. But it had some additional very interesting. For example, the ability to migrate the vm (while running) from one host to another. Or at least so they said. The problem. It didn’t have a decent GUI. All controlled by the command line. Of course I don’t have any problem with that, as my blog title very clearly states. But for some simple activities, the number of parameters to write was very overwhelming and, accustomed to VirtualBox simplicity, it was too much typing.
Well, this guys at Red Hat have created virt-manager. And it really aimed high in order to easy the management of vms. I am glad that they are succeeding in their goal, because virt-manager it is ready to take the datacenters by storm. In fact, Ubuntu 8.10 it is fully committed to the virtualization trend and virt-manager it is the tool they chose.
Well, enough words, I want to say to the VirtualBox team, thank you very much, your software it is marvelous and have showed what it is possible. At the same time I say welcome to KVM/virt-manager that, by the way, it is completely integrated to the Linux kernel and in the long term this will result in a very strong contender in the virtualization arena.

So, I followed the instructions from the debian wiki:

# aptitude install kvm virt-manager

Added myself to the libvirt group:

# adduser miguel libvirt

According to the instructions you must now log out and log in in order to use virt-manager and start creating vms for the dozen. But no, there is something you must do before. You must fix the network for virt-manager. Keep reading.

First stop dnsmasq:

# /etc/init.d/dnsmasq stop

Disable autostart for it editing /etc/default/dnsmasq and changing:

ENABLED=1

to

ENABLED=0

This is because virt-manager and libvirtd will start the dnsmasq with the appropriate configuration and the default config for dnsmasq conflicts with it and prevents the “default” network from virt-manager to start.

Now, log out, log in again, restart the libvirtd (or restart the machine) in order to the changes to take effect.

If everything works ok, you should see something like this in your processlist:

$ ps ax|grep dnsmasq
14482 ?        S      0:00 dnsmasq –keep-in-foreground –strict-order –bind-interfaces –pid-file  –conf-file  –listen-address 192.168.122.1 –except-interface lo –dhcp-leasefile=/var/lib/libvirt/dhcp-default.leases –dhcp-range 192.168.122.2,192.168.122.254

If you see a dnsmasq process with status Z (zombie), then review your configuration and the instructions.

Ok, with dnsmasq working correctly, start virt-manager as your user and try to connect to the localhost machine you’ll see in the virt-manager window. Before creating the first virtual machine, we must start the network. Click the “Details” button, after selecting localhost and you’ll see the “Host Details” dialog box. Select the “Virtual Network” tab. There you’ll see the “default” network in an inactive status (it only appears if you are connected to the machine). Start it. Now you can create your virtual machines without problems.

As you can see, the “default” network isn’t configured to autostart itself. And after a while, you get tired of starting it before running or creating a vm. To enable autostart, run the following in the command line (because I didn’t find a way to do it with the GUI):

$ virsh net-autostart default

From now on, the network will always start with the libvirtd.

Now, grab your prefered OS instalation CDs and proceed to create all the virtual machines you want.

Right now we have only used the functionality to create virtual machines in a analogous way to VirtualBox, but if you check the documentation for KVM and virt-manager, you’ll see that you can have a lot of host machines, remotely managed, where you can create virtual machines on demand. Also, you can monitor the resources consumed; start and stop the machines and to configure some kind of network storage for your virtual machines to use. Very enterprisey isn’t? Check the output of

$ virsh help

to have an idea that will come.