May 31 2016, 00:00#

KVM virtualization on Debian 8

Kernel-based Virtual Machine (KVM) is a virtualization module in the Linux kernel that allows the kernel to function as a hypervisor. We will see how to setup quickly a hypervisor on Debian 8 using KVM.

Prerequisites

Check processor flags

KVM requires a processor with hardware virtualization extensions, such as Intel VT or AMD-V. So, we have to check if our processor has such an extension.

egrep 'svm|vmx' /proc/cpuinfo

You have to see at least one result.

Packages

apt install qemu-kvm libvirt-bin virtinst

GUI

If you need a GUI to manage your VMs, you can install virt-manager.

apt install virt-manager

virt-manager is able to provide a GUI for local KVM instance, but also for remote instances.

Network configuration

The main way to setup the network for the VMs is to make a network bridge. You can read my post "Setting up a network bridge on Debian 7" about that.

When the network bridge is up, we can configure the KVM network.

Edit /etc/libvirt/qemu/networks/host-bridge.xml

<network>
  <name>host-bridge</name>
  <forward mode="bridge"/>
  <bridge name="br0"/>
</network>

Then

virsh net-define /etc/libvirt/qemu/networks/host-bridge.xml

Finally, start the network.

virsh net-start host-bridge

Create a new pool

Now we will create a default pool for our VMs in /srv/kvm

mkdir -p /srv/kvm
virsh pool-create-as default dir --target /srv/kvm

Create a new virtual machine

Here is an example of creating a new CentOS VM:

  • OS CentOS 7
  • Type Linux RHEL7 (Red Hat Enterprise Linux 7)
  • Memory 512M
  • Disk 8G (qcow2 format)
  • Network host-bridge (defined previously)

Creating a VM can be done just in one command

virt-install --connect qemu:///system \
--virt-type kvm \
--name centos7 \
--ram 512 \
--disk /srv/kvm/centos7.qcow,format=qcow2,size=8 \
--cdrom /media/iso/os/linux/CentOS-7-x86_64-Minimal-1511.iso \
-w network=host-bridge \
--vnc \
--os-type linux --os-variant rhel7

Need explanations about the arguments? Please, take a look in the manual.

man virt-install

libvirt group

If you want to manage your VMs without passing through the root user, you can add your user into the libvirt group.

gpasswd -a user libvirt

Tags : unix linux debian virtualization kvm