KVM on Debian GNU/Linux

KVM stands for Kernel based Virtual Machine, is the official virtualization system to Linux kernel, it is implemented as a Linux kernel module and becomes the running Linux in an hypervisor.

Without going deeply, the virtualization systems can be divided in some groups:

  • Emulation: VM simulates the full hardware, you can manage new hardware but you get low performance (qemu)
  • Full virtualization: similar to the first one but OS’s in guess machines will have to be from the same architecture (VirtualBox, KVM, XEN + VT, VMWare, Hyper-V)
  • Paravirtualization: VM has the same architecture, high performance, no VT required. Cons: you need to modify host machine (with a Linux kernel module) (XEN, KVM, Hyper-V)
  • OS level virtualization: there are some examples LXC, OpenVZ, FreeBSD Jails, … (thanks to @JavierCelaya)

LXC stands for Linux Containers, is the well known set of tools, templates, library and language bindings.


FreeBSD Jails allows to split a FreeBSD box into virtual environments running on the host machine called jails.


INSTALL WINDOWS7 (a perfectly legal one, of course 😉 )
As use case to introduce KVM I’m going to explain the installation process from virt-manager tool of Windows 7, feel free to use virt-install command to make the same process.
Before starting to install Windows 7 it’s necessary install some packages to be able to use KVM on Debian GNU/Linux, here is the command used:

 # aptitude install qemu-kvm libvirt-bin virt-manager virt-viewer

Let start with the set up process:

Select Create a new virtual machine option.
 Name: windows7
 Install from local ISO (in my case)
 Use ISO image
 OS Type: Windows
 Version: Windows7
 RAM: 2048
 CPUs: 2 (up to 4)
 Enable storage for this virtual machine
 Create disk image on the computer's HD 15 GB
 Allocate the entire disk now (check this option it depends on your needs)

If virt-manager detects that there is created img files with the same name of the new virtual machine it shows a message: The following storage already exists, but it’s not in use by any VM:

 Would you like to reuse this storage? No (in my case)

IMPORTANT: Check customize configuration before install option
Just as simple advice it would be fine check Advanced options, here we could play with network settings (perhaps I’ll talk about this in a future blog entry)

When you press Finish button a window appears to setup new hardware or remove the existing one, in our case I want to add other ISO image with libvirtio drivers to Windows7 see Virtio.

NOTE: In add hardware window if you select a hardware you’ll get the following error, I don’t know why but it seems that XML properties related to the virtual machine are not completely written.

Error refreshing hardware page: unsupported operand type(s) for /: 'NoneType' and 'int'

Press add hardware option, select managed or other existing storage
 Browse: virtio-win-0.1-65.iso
 Device type: IDE CDROM

Why install these drivers?

Para-virtualized drivers enhance the performance of fully virtualized guests. With the para-virtualized drivers guest I/O latency decreases and throughput increases to near bare-metal levels. It is recommended to use the para-virtualized drivers for fully virtualized guests running I/O heavy tasks and applications. From here. You could download drivers file from here.

Now we can press Begin Installation button. Just remember that you will have to select the virtio drivers from the extra storage that previously it has created, when Windows7 install process let you do it Custom Advanced > Load Driver > Browser.

Some useful commands

Thanks to @FranLopez:
Mount the CD-ROM iso (taking into account CD-ROM as IDE device):

virsh # attach-disk your_domain_name /path/to/your.iso hdc --type cdrom --mode readonly

Change the CD-ROM:

virsh # attach-disk your_domain_name /path/to/your/new.iso hdc --type cdrom --mode readonly

Remove the CD-ROM:

virsh # attach-disk your_domain_name " " hdc --type cdrom --mode readonly


Some points are not being discussed in this entry as:

  • Assigning Host USB device to a Guest VM take a look to this URL.
  • You could improve disk I/O performance following this instructions.
  • And last but not least if you need make a snapshot or convert an img storage file you could read this page.


I include this point in my entry because it could useful to know how remove virtual machines when you are doing tests with KVM.

$ virsh --connect qemu:///system undefine windows7
 Domain windows7 has been undefined

If you have virt-manager opened you will see as after executing the previous command the VM windows7 disappears from the list of managed virtual machines.

It’s not necessary to say that I’m not a virtualization expert, with this post I only want to collect some information about KVM that I’ve used installing some Windows VMs to be used in my own labs.

“Stay hungry, stay foolish”
–Steve Jobs (2005 Stanford Commencement)

One thought on “KVM on Debian GNU/Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s