Linux QEMU/KVM simple virtualization

Part of the Linux kernel is the KVM system, allowing users to run virtual computers with full the kernel support. QEMU (Quick Emulator) is a program that provides a easy way of running virtual machines with KVM. With a single command you can start a virtual machine with a GUI.

We will see  how you install and run a virtual Debian machine with only a few commands.

First we need to get a hold of QEMU/KVM. Assuming that you run a distribution with a packet manager, search for it and download it there.

On Debian it’s the packet qemu (apt-get install qemu).

When you have QEMU installed you need to download a installation ISO. Since we are going for a Debian installation in this tutorial, we’ll download one from their archive. At the time of writing I got a .iso file debian-8.5.0-amd64-i386-netinst.iso.

Now we need something to install the operating system on. We will use a virtual disk formated with QCow2. This comes with QEMU and we will create a 8 GB disk with this command:

qemu-img create -f qcow2 storage.qcow2 8G

The size of this disk will not actually be 8 GB. QCow2 does not occupy space in the file that has not yet been written to by the guest virtual machine. When I created the disk, the initial file size became 988 MB. Don’t worry about locking into the QCow2 format. qemu-img convert can be used to convert the disk file to a raw format.

Now we have everything to start the installation. We will start QEMU with our virtual disk as the primary disk and the downloaded .iso image as a CD-ROM source.

kvm -hda test.qcow2 -cdrom debian-8.5.0-amd64-i386-netinst.iso

A window will appear corresponding to the virtual machine monitor. To use the mouse click in the window, to unlock the mouse press CTRL+ALT. To put the window in full screen mode press CTRL+ALT+U.

Follow the installation instructions…

Debian QEMU/KVM
Debian QEMU/KVM

The virtual disk detected with the disk space previously specified.

Installation to virtual disk
Installation to virtual disk

If you didn’t encounter any problems the OS will be installed on the virtual disk.

Now you can run the virtual machine with this command:

kvm test.qcow2
Debian virtual guest
Debian virtual guest

Now you have a running virtual machine with a very simple configuration.

QEMU a lot more features. For example you can give the virtual machine full access to your GPU with something called VGA pass through. Check out this link for some other common virtual machine howto’s.

One thought on “Linux QEMU/KVM simple virtualization”

Leave a Reply

Your email address will not be published. Required fields are marked *