Virtualization with KVM and Debian Lenny

Posted byajgarlag onJanuary 17th 2010, at 2:04pm
by Red Hat, Inc.
debian, en, sysadmin, virtualization

Some weeks ago I've started to work with virtualized machines, and as an old Linux user, I've choosen KVM as virtualization infrastructure. KVM is part of the Linux kernel since the 2.6.20 version and Debian Lenny 5.0 was released with the 2.6.26 kernel version. But in order to work with KVM we need a CPU processor with virtualization support, so the first step is to check if our CPU has it. You have to execute:

egrep '(vmx|svm)' --color=always /proc/cpuinfo

Now you should see a colored flag for each processor core. If you see it, you can go ahead with the following steps.

Although we don't need any extra repository, I've decide to use the backports.org semi-official repository to take advantage of the more recent software releases. To enable it, type the following commands:

echo "deb http://www.backports.org/debian lenny-backports main contrib non-free" \
> /etc/apt/sources.list.d/backports.list && \
wget -O - http://backports.org/debian/archive.key | apt-key add - && \
aptitude update

Now, we have to install the required packages:

aptitude install -t lenny-backports kvm virtinst libvirt-bin

Finally we must prepare the network to allow the virtual machine to connect with the world. The Debian libvirt-bin package comes with a preconfigured private network (192.168.122.0/24) with a DHCP server managed with dnsmasq. This network is called default and if we need some virtual machine to start automatically after the host reboot, we have to start this network automatically too. We can do it with virsh, a Swiss knife command to manage our virtual machines with the help of libvirt.

virsh net-start default && virsh net-autostart default

Ok, we're ready to install our new virtual machine with the help of the virt-inst command. We will install a virtual machine named vmguest, with 512Mb or ram, running linux (Debian Lenny) using kvm as virtualization infrastructure. The disk will be allocated onto the host filesystem in a raw disk image (/opt/vmguest-root.disk) with a size of 20G and using virtio as the block device driver. The virtual machine will be connected to the default network with a virtio network card. The virtual machine will start a VNC server to allow you to connect to the screen and will disable the connection to the virtual machine serial console. Finally the default keymap will be es and the installer will be downloaded from an external location instead of using a cdrom image.

virt-install --name=vmguest \
--ram 512 \
--os-type linux --os-variant debianlenny \
--virt-type kvm \
--disk path=/opt/vmguest-root.disk,bus=virtio,size=20 \
-w network=default,model=virtio \
--vnc \
--noautoconsole \
--keymap es \
--location http://ftp.debian.org/debian/dists/lenny/main/installer-amd64

Now we have to connect to the virtual machine session in order to complete the installation. To do it I usually use virt-viewer through an ssh tunnel to connect to the host machine (remember to install it if you need it). To do it type:

virt-viewer -c qemu+ssh://root@host.machine/system vmguest

If you are directly connected to the host machine, you have to type as root:

virt-viewer -c qemu:///system vmguest

Ok, that's all. You ready to install your new Debian Lenny onto the virtual machine. Once installed, the virtual machines will be managed with the virsh command… but it will be on another host.

Edited: For this first post about KVM I think it's a better idea to save the disk onto the host filesystem, although I prefer LVM, because the file based disk image does not need any previous setup.

Edited 2: This post was written when the libvirt backport version was 0.6.5-3. I you have any problem with the latest backport packages you can download the old ones from snapshot.debian.org/package/libvirt/0.6.5-3~bpo50%2B1/

Any typo or problem? Edit this page on Github


Comments

Antonio J. García Lagar, onJanuary 28th 2010, at 3:58pm said:

After some days searching for a way to install Debian Lenny into the virtual machine with the console interface, I have it. You have to change the --vnc param for the --nographics param, remove the --noautoconsole param and add extra params to the installer kernel with -x "DEBIAN_FRONTEND=text console=ttyS0". This is the whole command:

virt-install --name=vmguest \
--ram 512 \
--os-type linux --os-variant debianlenny \
--virt-type kvm \
--disk path=/opt/vmguest-root.disk,bus=virtio,size=20 \
-w network=default,model=virtio \
--keymap es \
--location http://ftp.debian.org/debian/d...
-x "DEBIAN_FRONTEND=text console=ttyS0"

Mike, onSeptember 4th 2012, at 3:25pm said:

And how I am able to connect to the VM for doing installation via console?

Cheers,
Mike

Antonio J. García Lagar, onSeptember 5th 2012, at 12:49pm said:

You should run:

"virsh console vmguestname"

comments powered by Disqus