In this guide I will explain how to install and use KVM to create and run virtual machines on a Debian Squeeze Server.
In this tutorial I will show how to create image-based virtual machines.
KVM makes use of hardware virtualization. For that you need a CPU that supports hardware virtualization such as Intel VT or AMD-V.
Step 1. Check if your CPU supports hardware virtualization using the following command:
egrep ‘(vmx|svm)’ –color=always /proc/cpuinfo
If your result is nothing, then your processor doesn’t support hardware virtualization.
Step 2. Install KVM and virtinst :
apt-get install kvm qemu-kvm libvirt-bin virtinst
Step 3. Now we need to add the user as which we’re currently logged in to the groups libvirt and kvm. Run the following commands:
adduser `id -un` libvirt
adduser `id -un` kvm
Step 4. You also need to set up a network bridge on our server. You need that for virtual machines to can be accessed from outside.
For that you need to install the package bridge-utils.
apt-get install bridge-utils
Step 5. Configure the bridge:
Edit the /etc/network/interfaces file:
After edit your file should look something like this:
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet manual # The brigde configuration auto br0 iface br0 inet static address 192.168.4.100 network 192.168.4.0 netmask 255.255.255.0 broadcast 192.168.4.255 gateway 192.168.4.1 bridge_ports eth0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off
Now restart the network interfaces:
Step 6. Create the first virtual machine . In this example we will create a Debian Squeeze Guest using the command line:
In this example we will create the virtual machine named first-machine, with , 1024MB of RAM, 2 virtual CPU’s, and the disk image located in /var/lib/libvirt/images/first-machine.img, with a size of 5GB and using the image of the Debian Squeeze debian-126.96.36.199-i386-netinst.iso.
The command looks like this:
virt-install –connect qemu:///system -n first-machine -r 1024 –vcpus=2 –disk path=/var/lib/libvirt/images/firts-machine.img,size=5 -c /var/lib/libvirt/images/debian-188.8.131.52-i386-netinst.iso –vnc –noautoconsole –os-type linux –os-variant debiansqueeze –accelerate –network=bridge:br0 –hvm
And the output will look like this:
Allocating ’firts-machine.img’ | 5 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.
Step 7. For connecting to guest machine you will need a means of connecting to the graphical console. For that you will use virt-manager.
Use the following command to install virt-manager:
apt-get install virt-manager
Step 8. Connecting to the virtual machine. For that you need to have installed the graphic interface on your server.
You have 2 possibilities:
First is to acces directly the virt-manager application from Applications > System Tools > Virtual Machine Manager.
Second is acces the aplication from ssh using the command:
I also made a script that helps you to install and configure automaticaly KVM.
You can download it from here : http://www.debian-tutorials.com/scripts/debian-kvm
NOTE: For the seccond possibility you need to configure your ssh server to forward the X server.
If you have questions feel free to ask them here.