KVM Basics

Not everybody likes having a full invasive install of VMware Workstation, VirtualBox or virt-manager for that matter. Luckily KVM can be installed without pulling in too many dependancies or having to kludge in poorly maintained kernel modules.

Using KVM bare isn’t particularly difficult, first you’ll need to create a disk image (in this particular example 50GB thin provisioned):

qemu-img create -f qcow2 disk.img 50G
Formatting 'disk.img', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 ...

Next we’ll need to start KVM (assuming a Windows guest OS), for example:

kvm -m 2048 -localtime -monitor stdio -soundhw ac97 -usb -usbdevice tablet -hda disk.img

The -m 2048 parameter assigns 2GB of virtual RAM. The -localtime parameter should be included for non-UNIX operating systems that do not same save the systemclock as GMT. The -monitor stdio parameter allows KVM to be controlled using it’s monitor interface presented on the terminal it was started from. The -soundhw parameter allows you to select which audio hardware KVM should emulate, the optimal choice depends heavily on the guest operating system. The -usb -usbdevice tablet parameters tell KVM to emulate a tablet pointer which at least for Windows allows decent mouse performance without requiring a guest driver.

Once KVM is started, you’ll notice it’s monitor interface popping up on the terminal.

QEMU 2.0.0 monitor - type 'help' for more information

With this monitor interface you’ll be able to control the KVM virtual machine, for example changing/ejecting a emulated floppy disk image:

(qemu) change floppy0 myfloppy.img
(qemu) eject floppy0

Or configuring the KVM virtual machine to (re)boot from a CD-ROM image:

(qemu) change ide1-cd0 mycdrom.iso
(qemu) boot_set d 
(qemu) system_reset

Obviously there is more to KVM’s monitor interface, and of course it accepts a help command, which will provide you with an elaborate list of possibilities and options.