Monday, June 6, 2011

KVM bare metal as non-privileged user

I usually drive kvm via libvirt. Mostly via handcrafted xml files. But I want to run kvm (qemu-system-x86_64) directly without virsh and libvirt and ran into the following permission issue.

open /dev/kvm: Permission denied

Turns out ubuntu 10.04 does not grant permissions to "kvm" group on /dev/kvm. So I had to add an udev rule as specified in FAQ.

$ cat /etc/udev/rules.d/40-permissions.rules
KERNEL=="kvm", GROUP="kvm"

Trying to run on SDL did not work for me. I have a minimalistic host

(!) Direct/Util: opening '/dev/fb0' failed
--> Permission denied
(!) DirectFB/FBDev: Error opening framebuffer device!
(!) DirectFB/FBDev: Use 'fbdev' option or set FRAMEBUFFER environment variable.
(!) DirectFB/Core: Could not initialize 'system_core' core!
--> Initialization error!
Could not initialize SDL - exiting

-curses option did not work for me either, so I used vnc on a local port.

Here's the final command to launch kvm

$ qemu-system-x86_64 -hda ub1104-master.qcow2 -m 512 -boot d -cdrom /home/amitava/iso/ubuntu-1104-mini.iso -vnc "127.0.0.1:5"

And here's the command in my macbook to create an ssh tunnel for my vnc client (Chicken of the VNC)

$ ssh -L 5905:127.0.0.1:5905 # invoke vnc client afterwards

Now I have a master qcow2 image that I can clone in less than a minute to spawn a vm guest. And it takes just 14Mb for a guest with nginx-light - thanks to qemu's copy-on-write (COW).

On a final note - ubuntu 11.04 guest (minimal vm guest) boots fine but fails to show the login prompt. I had to switch to virtual console 2 and back to 1 (Ctrl+Alt+2 & Ctrl+Alt+1) to get the prompt.

No comments: