KVM virtualisation is a Kernel based virtualisation. It actually stands for Kernel-based Virtual Machine. It means that each of your virtual machine will have it´s own virtual hardware, such as network card, graphic card, memory and hard drive.
To setup KVM virtualisation it require a multicore cpu. And virtualisation needs to be activated in the BIOS. Look for virtualisation, Intel VT-x (vmx) or AMD-v settings, and enable it. You might be able to install KVM without virtualisation enabled in the BIOS. But the virtual machines will be extremely slow.
Here is how to install KVM on a minimal Debian installation.
First we assume a ssh server is installed, and sudo.
Step 1: First we install the essential packages for KVM. apt-get install kvm libvirt-bin virtinst bridge-utils
If you want to be able to controll the virtual machines from your own users instead of root. Add your user to the libvirt group. adduser john libvirt
Step 2: To be able to give network access to your virtual computers you will need to bridge your network card. To do this we will change the network interface file. (Change the ip´s to match your network) nano /etc/network/interfaces
# 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 iface eth0 inet manual
I prefer using a gui when controlling my virtual machines. Learning how to control them in the most basic way from the command line or terminal is easy. It is very self explanatory once you know about the virsh command. I have made some examples below on how to use these commands.
Here is the list of basic commands to start, stop and reboot your virtual machines.
List your running guests
virsh list [sourcecode language=”text”] Id Name State —————————————————- 2 apt-cacher.home running [/sourcecode]
List all guests:
virsh list –all [sourcecode language=”text”] Id Name State —————————————————- 2 apt-cacher.home running – db1.home shut off – db2.home shut off – devlab.home shut off – minecraft.home shut off – vault.home shut off – web.home shut off [/sourcecode]
To start a vm
we can only use their vm name to start them. virsh start db1.home
To reboot a vm
We can use name or id to reboot the vm. virsh reboot 2 virsh reboot apt-cacher.home
The Virtual Machine Manager is a small powerful tool when it comes to handling your kvm guests. To install the Virtual Machine Manager we do: apt-get install virt-manager
It is now ready to run. However to connect to your KVM hosts you need also to install a ssh askpass software. apt-get install ssh-askpass
First time you connect to your host you need to confirm the fingerprint. If you have accessed the host via ssh, and done re-installs, chances are the fingerprint won’t match. One simple solution to this is to delete the known_hosts file, or modify it if you are comfortable doing that. Normally on a Debian based system it’s located (example assume user is jondoe): /home/jondoe/.ssh/known_hosts