Virtualization With KVM On A Debian Lenny Server

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2009-03-15 20:32. :: Debian | KVM | Virtualization

Virtualization With KVM On A Debian Lenny Server

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 03/09/2009

This guide explains how you can install and use KVM for creating and running virtual machines on a Debian Lenny server. I will show how to create image-based virtual machines and also virtual machines that use a logical volume (LVM). KVM is short for Kernel-based Virtual Machine and makes use of hardware virtualization, i.e., you need a CPU that supports hardware virtualization, e.g. Intel VT or AMD-V.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I'm using a machine with the hostname server1.example.com and the IP address 192.168.0.100 here as my KVM host.

We also need a desktop system where we install virt-manager so that we can connect to the graphical console of the virtual machines that we install. I'm using an Ubuntu 8.10 desktop here.

 

2 Installing KVM

Debian Lenny KVM Host:

First check if your CPU supports hardware virtualization - if this is the case, the command

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

should display something, e.g. like this:

server1:~# egrep '(vmx|svm)' --color=always /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
 nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy 3dnowprefetch
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
 nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy 3dnowprefetch
server1:~#

If nothing is displayed, then your processor doesn't support hardware virtualization, and you must stop here.

To install KVM and virtinst (a tool to create virtual machines), we run

aptitude install kvm libvirt-bin virtinst

Afterwards we must add the user as which we're currently logged in (root) to the group libvirt:

adduser `id -un` libvirt

You need to log out and log back in for the new group membership to take effect.

To check if KVM has successfully been installed, run

virsh -c qemu:///system list

It should display something like this:

server1:~# virsh -c qemu:///system list
 Id Name                 State
----------------------------------

server1:~#

If it displays an error instead, then something went wrong.

Next we need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network.

To do this, we install the package bridge-utils...

aptitude install bridge-utils

... and configure a bridge. Open /etc/network/interfaces:

vi /etc/network/interfaces

Before the modification, my file looks as follows:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
        address 192.168.0.100
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1

I change it so that it looks like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
        address 192.168.0.100
        network 192.168.0.0
        netmask 255.255.255.0
        broadcast 192.168.0.255
        gateway 192.168.0.1
        bridge_ports eth0
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off

(Make sure you use the correct settings for your network!)

Restart the network...

/etc/init.d/networking restart

... and run

ifconfig

It should now show the network bridge (br0):

server1:~# ifconfig
br0       Link encap:Ethernet  HWaddr 00:1e:90:f3:f0:02
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:350 (350.0 B)  TX bytes:1456 (1.4 KiB)

eth0      Link encap:Ethernet  HWaddr 00:1e:90:f3:f0:02
          inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:43262 errors:0 dropped:0 overruns:0 frame:0
          TX packets:23574 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:63379451 (60.4 MiB)  TX bytes:1868584 (1.7 MiB)
          Interrupt:251 Base address:0xc000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:560 (560.0 B)  TX bytes:560 (560.0 B)

server1:~#

 

3 Installing virt-viewer Or virt-manager On Your Ubuntu 8.10 Desktop

Ubuntu 8.10 Desktop:

We need a means of connecting to the graphical console of our guests - we can use virt-manager (see KVM Guest Management With Virt-Manager On Ubuntu 8.10) for this. I'm assuming that you're using an Ubuntu 8.10 desktop.

Run

sudo aptitude install virt-manager

to install virt-manager.

 

4 Creating A Debian Lenny Guest (Image-Based)

Debian Lenny KVM Host:

Now let's go back to our Debian Lenny KVM host.

Take a look at

man virt-install

to learn how to use it.

To create a Debian Lenny guest (in bridging mode) with the name vm10, 512MB of RAM, two virtual CPUs, and the disk image ~/vm10.qcow2 (with a size of 12GB), insert the Debian Lenny Netinstall CD into the CD drive and run

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 -f ~/vm10.qcow2 -s 12 -c /dev/cdrom --vnc --noautoconsole --os-type linux --os-variant debianLenny --accelerate --network=bridge:br0 --hvm

Of course, you can also create an ISO image of the Debian Lenny Netinstall CD...

dd if=/dev/cdrom of=~/debian-500-amd64-netinst.iso

... and use the ISO image in the virt-install command:

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 -f ~/vm10.qcow2 -s 12 -c ~/debian-500-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debianLenny --accelerate --network=bridge:br0 --hvm

The output is as follows:

server1:~# virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 -f ~/vm10.qcow2 -s 12 -c ~/debian-500-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debianLenny --accelerate --network=bridge:br0 --hvm


Starting install...
Creating storage file...  100% |=========================|  12 GB    00:00
Creating domain...                                                 0 B 00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
server1:~#


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by gabrielsaragoca (registered user) on Fri, 2014-05-02 18:58.

KVM is a full virtualization solution for Linux on x86 (64-bit included) hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko.

 

 

Submitted by Anonymous (not registered) on Fri, 2011-10-14 04:29.
Very nice writeup! Thanks!
Submitted by Anonymous (not registered) on Thu, 2010-10-28 05:27.
everything fine except for the title, you may change it to: Virtualization on Ubuntu 8.10 Desktop