Installing Kernel-based Virtual Machine (KVM) on Debian 7

debianBefore you even install KVM on your freshly installed Debian machine, you need to make sure that your machine can even run the KVM virtualization. Most computers will have to enable virtualization through the BIOS as it is mostly disabled by default.
And you will get an error when you try and install KVM. There are even some computers that can not run it all together.

The most common way to enable virtualization is by pressing either F8 or F12 as your machine starts up, to enter the BIOS. Look for System Configuration and Enable Virtualization Software.
Keep in mind that this is different from machine to machine and could be something entirely different, and the steps might be a bit more convoluted, so you might have to do a little search on the internet to work out how to do exactly it on your computer.

When that is done save and reboot the pc, and let it load up your Debian. Go to the top left corner click on Applications -> Accessories -> Root Terminal and type the password for the Root user.

As you have done that you don’t need to type su before every command as su is already enabled.

Before you do anything you will need the MAC address of your computer, to get that just type the command:


And look for HWaddr. There should be some numbers and letters divided in groups of 6 with semicolon. Write these down as you are going to use it later.

The next step is to update and upgrade any software and stuff on your Debian to do this simply type:

apt-get update
apt-get dist-upgrade

After all the things are updated and upgraded, comes the time to actually install KVM.
To do this type:

aptitude –y install quemu-kvm libvirt-bin virtinst bridge-utils

And then add the username of the of the user of the computer. (this is not the root)
To do that type:

adduser “username here” libvirt

The next thing we need to do is to enable vhost_net
Simply type these three commands and it should be up and running.

modprobe vhost_net
lsmod | grep vhost
echo vhost_net >> /etc/modules

The last thing we need to do is to set up the bridge interface, as KVM will get the same IP and internet connection as the computer.
To get to the configuration file type in this command:

nano /etc/network/interfaces

You should see something that looks like what I have written below here, go to the field under the pre-existing text and put in what I have highlighted in Bold.
It is here you need to insert the MAC address you found earlier.

# The loopback network interface
 auto lo
 iface lo inet loopback

#auto eth0
 #iface eth0 inet dhcp

#The bridge network interface
 auto br0
 iface br0 inet DHCP
 hwaddress (insert the MAC address here)
 bridge_ports eth0
 bridge_stp off
 bridge_fd 0
 bridge_maxwait 0

This will set up the Bridge interface, and as you can see should get an IP address automatically through DHCP.

The last thing to do is to restart the service, and your KVM should now be install and operational.
To do that you type in this command:

service networking restart

The last thing you might want to do is to install the graphical user interface also called the Virtual Machine Manager.
To do that just type in the command:

aptitude -y install virt-manager

It should now be on you computer if you go under Applications -> System Tools -> Virtual Machine Manager.

You are now ready to create virtual machines using KVM.