A quick look about KVM (http://kvm.qumranet.com/kvmwiki/KVM-Wiki):
KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware. It consists of a loadable kernel module (kvm.ko) and a userspace component.
Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.
The kernel component of KVM is included in mainline Linux, and will appear in Linux 2.6.20.
KVM is open source software.
So how to set it up under Debian? Since KVM is still under active development, using Debian sid (unstable) would be a good idea; on the other hand, a VT supported CPU is also required; finally, you should have X11 installed. You may handle the setup of KVM client in many different way: manual command line parameter, custom pre-defined start/stop/config shell scripting, or by using libvirt + virt-manager. For this simple mini-HOWTO, I will guide you though the 1st solution with the least dependence.
Prepare your Debian sid
First of all, let's setup your APT with unstable/testing/stable hybrid support. Here is my /etc/apt/sources.list as reference:
deb http://ftp.hk.debian.org/debian/ stable main contrib non-free
deb-src http://ftp.hk.debian.org/debian/ stable main contrib non-free
deb http://ftp.jp.debian.org/debian/ stable main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ stable main contrib non-free
deb http://ftp.hk.debian.org/debian/ testing main contrib non-free
deb-src http://ftp.hk.debian.org/debian/ testing main contrib non-free
deb http://ftp.jp.debian.org/debian/ testing main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ testing main contrib non-free
deb http://ftp.hk.debian.org/debian/ unstable main contrib non-free
deb-src http://ftp.hk.debian.org/debian/ unstable main contrib non-free
deb http://ftp.jp.debian.org/debian/ unstable main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ unstable main contrib non-free
deb http://volatile.debian.org/debian-volatile stable/volatile main contrib non-free
deb http://security.debian.org/ stable/updates main contrib non-free
deb-src http://security.debian.org/ stable/updates main contrib non-free
deb http://ftp.debian-unofficial.org/debian unstable main contrib non-free restricted
deb-src http://ftp.debian-unofficial.org/debian unstable main contrib non-free restrictedYou may also setup /etc/apt/preference as below for additional APT-pinning handle (this example pin your Debian as unstable, check its priorities according to your needs):
Package: *
Pin: release a=stable
Pin-Priority: 600
Package: *
Pin: release a=testing
Pin-Priority: 650
Package: *
Pin: release a=unstable
Pin-Priority: 700Moreover, you will need to create /etc/apt/apt.conf.d/99cache as below, or else your cache may be busted:
APT::Cache-Limit "134217728";Whatever you are now using Debian stable/testing, just run the following command and upgrade your Debian as unstable, install latest Linux kernel + kernal header + KVM + module-assistant, and install kqemu plug-in as spare:
apt-get update
apt-get dist-upgrade
apt-get install linux-image-2.6-amd64 linux-headers-2.6-amd64 kvm module-assistant
module-assistant auto-install kqemuAfter reboot, check your kernel version with uname -a, e.g.:
Linux dc.edin.no-ip.com 2.6.24-1-amd64 #1 SMP Mon Feb 11 13:47:43 UTC 2008 x86_64 GNU/LinuxSetup your hardware and network
Let's probe KVM required modules:
modprobe kvm_amd kvm kqemuAnd check the result with lsmod
Next we should setup the network connection. Before further configuration, stop your current active network interface:
ifdown eth0 Edit /etc/network/interface as like as below, e.g. replace the original eth0 configuration as br0, and add other required parameters:
auto br0
iface br0 inet static
address 192.168.2.4
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
gateway 192.168.2.2
bridge_ports eth0
bridge_stp off
bridge_maxwait 5Now start the new interface with:
ifup br0Some kernel parameters are required, too. Add the following lines in /etc/sysctl.conf:
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0Load the new setting with:
sysctl -pFor further more details of libvirt networking, please refer to here:
http://libvirt.org/formatnetwork.html#examplesNAT
http://wiki.libvirt.org/page/Networking
Reboot, and check your network with ifconfig.
Create KVM client disk image
I would like to suggest hold all your KVM client disk image under a specific directory, e.g.:
mkdir -p /srv/demoGo to that directory and run the following command (32GB image with qcow2 format):
qemu-image create -f qcow2 /srv/demo/hda.qcow2 32GStart your KVM client
Assume you hope to install Debian stable in this KVM client (prepare you debian-40r3-i386-netinst.iso in /srv), run the following command to start the image (you should run kvm --help for more detail of this configuration):
kvm -hda /srv/demo/hda.qcow2 -net tap,vlan=0 -m 256 -vnc :0 -k en-us -daemonize -cdrom /srv/debian-40r3-i386-netinst.iso -boot dThen use any VNC client, and connect to this KVM client (e.g. localhost:5900). Start the installation and enjoy with it :)


















Post new comment