Nov 25 2008

Create a Virtual Machine with Debian Etch amd64 on KVM with virt-manager

This is the way I create virtual machines using KVM and virt-manager on my Debian Lenny 64 bit laptop:

  • I will create a 64 bit virtual machine
  • I will install Debian Etch 64 bit
  • I will install a Standard system. After installation I will install the required software as needed.
  • The machine will have a dynamic growing image file.
  • I will use the default network provided by virt-manager (see this). This means that:
    • the laptop (the host machine) will get a second IP address (192.168.122.1) that will be the default router for the virtual machines
    • the virtual machines will get addresses in the range 192.168.122.2 - 192.168.122.254
  • I will create a pair of ssh keys to log in to the machine without password

Here we go:

1. Make sure you have hardware virtualization enabled on your BIOS.
Search google for the instructions

2. Install KVM and virt-manager
Follow this instructions

3. Open virt-manager and connect to localhost

4. Start the network if you don’t have it configured for autostart
On the localhost host machine, select “Details” and then the “Virtual networks” tab. Select the “default” network and press the “Start” button.

5. Create a new virtual machine
On the localhost host machine, select “New”

6. “Naming your virtual system” window
Name your virtual machine, for example kvm

7. “Choosing a virtualization method”
I don’t have Xen, so the “Paravirtualized” options is disabled.
With “Fully virtualized” you can emulate a wider range of CPU architectures. In this time we are only interested in the x86_64 architecture. So we choose CPU Architecture: x86_64 and Hypervisor: kvm.

8. “Choosing installation method”
Here we choose the source installation media. I have an ISO image file from Debian Etch amd64, but you can also use networks install trees over HTTP, FTP or NFS or directly boot with PXE from a network server. When you chose OS Type and OS Variant, virt-manager preselects sensible defaults for the virtual machine, like ACPI support. We choose OS Type: Linux and OS Variant: Debian Etch.

9. “Locating installation media”
If you selected local install media in the previous step, you must choose either the ISO image location or the CD-ROM/DVD device where the install media resides. If you chose another option in the previous step, this window will differ. Enter the correct parameters here.

10. “Assigning storage space”
We choose “Simple File” unless you want to use a spare disk partition for your virtual machine. Select the File Location where you want your virtual machine image to reside and select an appropriate File Size. I left the defaults untouched. Uncheck the option “Allocate entire virtual disk now?”. This way the disk will grow as needed, unless you run out of disk space in your host machine.

11. “Connect to host network”
Unless you know what you are doing, do like me and choose “Virtual Network”. Select the “default” network from the list.

12. “Allocate memory and CPU”
Select the amount of RAM that you want to assign to the virtual machine. I wrote 256M both for VM Max Memory and VM Startup Memory. For VCPU choose the number of CPUs for the virtual machine. I chose 1 VCPU.

The image will be created and the virtual machine will boot up. By default virt-manager doesn’t open a VNC connection to the newly created machine. Double click the machine from the list below localhost to open it.
Follow the installation as always. Create a normal user (I created a user named miguel) and in the window titled “Software Selection” select the packages you want to install (I only left “Standard system” selected; after install you can install more software with aptitude). When the installation is over, it will reboot and you should log in without problems. As root check the IP assigned by the KVM DHCP. Mine has 192.168.122.137.
Now, in your host machine, add a new line for the virtual machine to your /etc/hosts. This is mine:

127.0.0.1 localhost
127.0.1.1 laptop.localdomain laptop
192.168.122.137 kvm

Save it and check that you can reach the virtual machine.

# ping kvm

should respond the pings.

Now, as the normal user from the host machine, create a pair of keys. Accept the default path for the keys and leave the passphrase empty.

miguel@laptop:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/miguel/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/miguel/.ssh/id_rsa.
Your public key has been saved in /home/miguel/.ssh/id_rsa.pub.
The key fingerprint is:
70:b5:bf:39:e4:4d:14:1d:ad:c6:f0:1f:c7:8f:26:15 miguel@laptop

This should have created 2 files inside .ssh/ in your home directory: id_rsa and id_rsa.pub
Now copy your identity to the virtual machine:

miguel@laptop:~$ ssh-copy-id kvm
miguel@kvm’s password:

Write your password and the key will be copied to the virtual machine. Test that you can log in without password:

miguel@laptop:~$ ssh kvm
Linux kvm 2.6.18-6-amd64 #1 SMP Wed Oct 15 10:07:11 UTC 2008 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Nov 25 16:08:19 2008 from laptop
miguel@kvm:~$

There you have it. A virtual machine running from KVM, with hardware virtualization, a minimal install and that you can log in without password.

You can also create a virtual machine and host a 32 bit OS. Just follow the previous steps but instead of installing from a Debian Etch amd64 ISO image, install from a Debian Etch i386 ISO image. That is, select a 64 bit virtual machine but install a 32 bit OS. This works for any operating system.

Of course you can choose CPU Architecture: i686, but the only hypervisor available will be qemu that will emulate by software (instead of doing hardware virtualization) the i386 (or sparc or ppc) architecture. This can be potentially slower than hardware virtualization.

Enjoy!


Nov 22 2008

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. 


Feb 22 2008

Virtualbox OSE on Debian GNU/Linux amd64

I use to have virtualbox installed in my machine from the packages provided by virtualbox.org.A few week ago I replaced it with the OSE available from the Debian repositories.

One package that wasn’t available for my architecture (amd64) was virtualbox-ose-modules.

Installing virtualbox-ose went without problems but when I started a virtualbox I received a message like:


VirtualBox kernel driver not installed. The vboxdrv kernel module was either not loaded or
/dev/vboxdrv was not created for some reason. Please install the virtualbox-ose-modules package
for your kernel and execute '/etc/init.d/vboxdrv start' as root.
VBox status code: -1908 (VERR_VM_DRIVER_NOT_INSTALLED).

Asking Mr. Google “he” gave me the answer by pointing his artificial finger to:

http://www.esdebian.org/forum/print.php?id=115990&forum=15

and to:

http://debaday.debian.net/2007/12/05/virtualbox-a-virtual-pc-for-you/

So I did, as root:


# aptitude install virtualbox-ose-source module-assistant
# m-a prepare virtualbox
# m-a a-i virtualbox
# dpkg -i /usr/src/virtualbox-ose-modules-*
# modprobe vboxdrv

and after that virtualbox worked like a charm


Mar 1 2007

VirtualBox

Como en el 90% de los trabajos, el sistema operativo de cabecera es alguna versión de Windows. Mi actual trabajo no es la excepción.
Y no hay nada más aburrido que un Windows con Office como único software instalado. Si quieres tener una máquina interesante debes instalarle un mundo de software para que los 3GHz y 1GB de memoria RAM sirvan para algo mejor que para escribir documentos, oficios y presentaciones. Pero instalar software en Windows es poco menos que cavernícola, sobre todo después de haber usado Debian. Tienes que buscar el software que necesitas, descargar la versión más reciente y esperar que instale todo en c:\Archivos de programa\ en lugar de c:\Program Files\. Si todo sale bien, ya tienes tu software instalado. Repite esto N veces y después de un par de horas tienes un sistema más o menos decente. Todo bien hasta que alguien te dice que existe una nueva versión de tal software.
Entonces repites el proceso de instalación para dicho paquete. Y una vez más para otro software y así hasta el infinito por los siglos de los siglos. ¡Qué flojera!

› Continue reading