Monday, October 22nd, 2007
Using Linux KVM Virtualization on Ubuntu Gutsy Gibbon 7.10
I _really_ like KVM (Kernel-based Virtual Machines) . It’s extremely simple to setup and use and lacks the intrusiveness of hypervisors like VMware and Xen. In this post, I’ll show you how to setup KVM on the latest Ubuntu 7.10 “Gutsy Gibbon”. Ubuntu already has a decent howto available here that walks you through the steps, but I’ll go a few steps further in places (and shorter in others) using the new Gutsy Gibbon release.
First off, you need a system with full virtualization enabled processors, or virtualization assist. AMD calls this Secure Virtual Machine (or SVM) and Intel calls its technology VT-x (or vmx). You can read more about this at LWN if you would like here.
I’m using Ubuntu 7.10 64-bit on an AMD64×2 dual core processor that has the AMD hardware virtualization assist extensions . To find out if your processor supports this, use the following command:
# egrep ‘(vmx|svm)’ /proc/cpuinfo
Example output from an AMD system (hence, “svm” is highlighted). If this were Intel based, you would see “vmx”:

First, start by installing KVM and QEMU using apt-get or Synaptic Package Manager
# apt-get install qemu kvm
# modprobe kvm-amd (or kvm-intel for intel procs)
Note that if you do not modprobe the KVM module, you will get an error such as the following when you try to start KVM in the steps that follow:

Installing an Ubuntu 7.10 Gutsy Gibbon server guest OS
# qemu-img create gutsy-server.img -f qcow2 6G
This creates a file for your virtual machine image in your current directory. QEMU and KVM actually support many other useful file formats as described in the qemu documentation. One of the more userful options here is to use “-f vmdk” as the vm image that you create and setup will be compatible with VMware 3 and 4. Obviously the ability to export and use the same image with VMware can be valuable.
One question you may have at this point is “why use KVM; doesn’t QEMU do this too?”. The simple answer is that KVM uses processor extensions for virtualization whereas QEMU uses processor emulation. QEMU emulates the processor and system devices. KVM does not need to emulate the processor but relies on QEMU to do its device emulation. The interesting use case for QEMU is that it can also emulate other processor architectures such as SPARC, PowerPC and MIPS (see this website) on an x86 host. While the difference may seem subtle, there are definite performance advantages to KVM (and once can assume stability advantages). Someday, we may see them merge… but I doubt it. You can find a great overview of the differences between various Linux virtualization technologies at developerWorks here.
Back to KVM, the command above creates an image file that grows as the VM requires. With an inflatable disk image, your VM grows with the space used by the virtual machine up to 6GB (versus pre-allocating a full 6GB disk image). Now, let’s startup an Ubuntu install for our new virtual machine.
# kvm -m 750 -cdrom /home/user/ubuntu-7.10-server-amd64.iso -boot d ubuntu-server.img
For new users, the /home/user/ should just be the path to where you stored your Ubuntu iso download. If you execute this command and only see a black window pop up that looks empty, you can hit enter to start the install and the screen will come back. Or, you can add “-std-vga” to the kvm command above to help with the framebuffer Ubuntu startup.
This will start up KVM and boot the virtual machine off of the Ubuntu iso image. You can also boot from a CD/DVD drive by using this command:
# kvm -m 750 -cdrom /dev/cdrom -boot d ubuntu-server.img
Once you execute the command, QEMU will startup and you will see the normal boot options as if you started your computer with an Ubuntu install disk in the drive. I had to use -no-acpi with Ubuntu 7.10 or else I would get kernel panics once it went to install. The title bar should show QEMU/KVM. If you just see QEMU (as in the image below), then KVM failed (you most likely forgot to load the KVM module in the steps above) and you should exit even though it appears to be working. If you see QEMU/KVM, you should now have a working KVM install. Continue with the server install process and configuration as usual.
Once installation is finished, the Ubuntu guest will try to restart. This will fail, and that’s fine. You can close out the QEMU/KVM window, return to the command line, and start up your KVM guest Ubuntu server for the first time. I also tend to give running guests less memory than during the install…
# kvm -no-acpi -m 500 ubuntu-server.img
(note that I installed the text based version of Ubuntu server with no GUI or X windows)
Fedora Core 8 Beta as a KVM Guest
I’ll create an image for Fedora 8 first, using vmdk as the file format to later use this same image with VMware. You can click here for more information on how to use a QEMU created vmdk file in VMware.
# qemu-create fedora8.img -f vmdk 6G
# kvm -no-acpi -m 750 -cdrom /dev/cdrom -boot d fedora8.img
# kvm -no-acpi -m 500 fedora8.img
Windows Server 2008 in KVM with Ubuntu:
See my post here for setting up Windows Server 2008 in KVM
Next up: managing KVM processes, KVM networking, and sharing files between host and guests.
Other Resources to Check Out:
Virtual disk images: http://fabrice.bellard.free.fr/qemu/qemu-doc.html#SEC24
KVM Wiki: http://kvm.qumranet.com/kvmwiki/Front_Page




October 23rd, 2007 at 9:43 am
Crear máquinas virtuales en Ubuntu 7.10 Gutsy : ayudaUbuntu.com said:
[...] tenéis el enlace de Michael Dolan Dot Com: Using Linux KVM Virtualization on Ubuntu Gutsy Gibbon 7.10 Envía esta entrada: Envía esta [...]
October 24th, 2007 at 1:24 am
tecosystems » links for 2007-10-24 said:
[...] Using Linux KVM Virtualization on Ubuntu Gutsy Gibbon 7.10 soon as i get Ubuntu back on my workstation, i’ll try this. thanks to mdolan for providing it. (tags: linux ubuntu virtualization kvm qemu hypervisor vmware xen) [...]
October 25th, 2007 at 7:21 pm
Tim said:
Hey, this was a great howto, I found it very straightforward and informative. Thanks!
October 26th, 2007 at 6:23 pm
Simon Scullion » links for 2007-10-26 said:
[...] Using Linux KVM Virtualization on Ubuntu Gutsy Gibbon 7.10 I _really_ like KVM (Kernel-based Virtual Machines) . It’s extremely simple to setup and use and lacks the intrusiveness of hypervisors like VMware and Xen. In this post, I’ll show you how to setup KVM on the latest Ubuntu 7.10 “Gutsy Gibbon”. (tags: linux ubuntu vmware virtualization kvm) [...]
October 31st, 2007 at 5:20 pm
Running Windows Server 2008 in KVM on Linux said:
[...] See my prior post on KVM if you want to get started with KVM setup. Assuming you have KVM working on your system, it takes just 3 easy steps to get started using Windows Server 2008 on Linux in KVM. Before starting, you must have a copy of Windows Server 2008 of course. If you don’t have one handy, you can download and burn an eval DVD ISO from here. [...]
November 3rd, 2007 at 11:05 am
Neal McBurnett said:
Excellent article – thanks!
I didn’t have to touch /dev/kvm – the modprobe created it this way:
crw-rw—- 1 root kvm 10, 232 2007-11-03 11:03 /dev/kvm
and so rather than chmod 777 /dev/kvm
it seems to me that adding the current user to the kvm group (”sudo adduser $LOGNAME kvm”)
would fit the way it is packaged better.
November 4th, 2007 at 1:23 pm
Javi said:
Great tutorial. Very clean.
Maybe you should describe kvm parameters better. ;-)
Nice job
November 5th, 2007 at 9:20 pm
Mike Dolan said:
Neal, you’re probably right – I actually tried to start KVM, got an error, then realized I hadn’t loaded it with modprobe yet. So I created it. I’ll actually edit the post to reflect your (proper) way.
Javi, what about the parameters would you like to see more explanation on?
December 5th, 2007 at 7:08 pm
Amr said:
Hey Neal, thanks for a great tutorial. I just installed KVM on Ubuntu-GG and it seems to work fine except that I get the ‘rtc: lost some interrupts at 1024Hz’ errors. I already did the “echo 1024 > /proc/sys/dev/rtc/max-user-freq” bit but still getting this real tim clock related error.
Any ideas on how this could be worked around or fixed? (U-GG kernel 2.6.22.x kvm+qemu on amd-4800 dual core).
Any pointers greatly appreciated! cheers.
December 10th, 2007 at 4:55 pm
EB said:
I installed ubuntu-gg server install on dell dual quad xenon with 16gb ram. Followed the instructions. modprobe kvm-intel worked fine. Installing ubuntu-gg server as guest OS didn´t go so well (su root). I received the:
> (!) Direct/Util: opening ‘/dev/fb0′ and ‘/dev/fb/0′ failed
> –> No such file or directory
> (!) DirectFB./FBDev: Error opening framebuffer device!
> (!) DirectFB/FBDev: Use ‘fbdev’ option or set FRAMEBUFFER environment variable.
> (!) DirectFB/Core: Could not initialize ’system’ core!
> –> Initialization error!
> Could not initialize SDL – exiting
error. Same with adding the -std-vga.
I installed x-window-system and ran gdm and then run a terminal window (su root) and try again. 2nd window pops up and goes away with exeption error in my working window:
root@ncesvr003:/var/vm# kvm -m 1024 -std-vga -cdrom /dev/cdrom -boot d ubuntu-server.img
exception 6 (0)
rax 0000000000000469 rbx 0000000000800001 rcx 0000000000004300 rdx 0000000000000000
rsi 000000000005961d rdi 000000000005961c rsp 00000000fffaa9cc rbp 000000000000200c
r8 0000000000000000 r9 0000000000000000 r10 0000000000000000 r11 0000000000000000
r12 0000000000000000 r13 0000000000000000 r14 0000000000000000 r15 0000000000000000
rip 000000000000b04b rflags 00033006
cs 4143 (00041430/0000ffff p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
ds 4004 (00040040/0000ffff p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
es 4004 (00040040/0000ffff p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
ss 0000 (00000000/0000ffff p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
fs 3002 (00030020/0000ffff p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
gs 0000 (00000000/0000ffff p 1 dpl 3 db 0 s 1 type 3 l 0 g 0 avl 0)
tr 0000 (40850000/00002088 p 1 dpl 0 db 0 s 0 type b l 0 g 0 avl 0)
ldt 0000 (00000000/0000ffff p 1 dpl 0 db 0 s 0 type 2 l 0 g 0 avl 0)
gdt 40920/47
idt 0/ffff
cr0 60000010 cr2 0 cr3 0 cr4 0 cr8 0 efer 0
code: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Aborted (core dumped)
root@ncesvr003:/var/vm#
Maybe it´s the 64-bit 2 quadcore XENON cpu´s ubuntu 7.10 on top of ubuntu 7.10. I tried -smp 1 as well as -smp 2 and -smp 8 just for kicks. Maybe the KVM doesn´t quite support the 2 XENONs yet. I guess I will try the Fedora Core 8 and see what happens unless anybody has any ideas. I´m at a loss.
December 11th, 2007 at 5:35 pm
md said:
I’m using a dual core AMD… I don’t even have access to the hardware you’re testing on to say it’s the hardware or not. It looks like you FB support is the problem though – at what point did this error come up (e.g. what was the command you issued that generated this error?)
December 16th, 2007 at 4:04 pm
Pete said:
I added the user to the kvm group and confirmed it,
pr@AMD:~$ sudo adduser pr kvm
The user `pr’ is already a member of `kvm’.
Then, with this command,
pr@AMD:~$ kvm -std-vga -m 750 -cdrom /home/pr/kubuntu-7.10-desktop-amd64.iso -boot d gutsy-desktop.img
open /dev/kvm: Permission denied
Could not initialize KVM, will disable KVM support
I see the Kubuntu install screen in the QEMU/KVM screen but when I try and install I get a “I/O Error Error Reading Boot CD”
…when I enter this command,
sudo kvm -std-vga -m 750 -cdrom /home/pr/kubuntu-7.10-desktop-amd64.iso -boot d gutsy-desktop.img
I just get the “I/O Error Error Reading Boot CD” error in the QEMU/KVM screen,
I also tried chmod 777 /dev/kvm, same results as above.
(HP Pavillion AMD 64 bit)
Any suggestions?
Thanks,
pr
December 17th, 2007 at 12:48 am
md said:
Did you run “modprobe kvm-amd”?
December 19th, 2007 at 8:35 am
cheezo said:
Hi
I have Ubuntu Gutsy Gibbon on an Intel Core Duo Laptop.
I also face a similar issue as mentioned above
root@hells-kitchen:~# kvm -m 750 -cdrom /media/cdrom0/ubuntu-7.10-desktop-i386.iso -boot d gutsy-server.img -std-vga
———————- DirectFB v0.9.25 ———————
(c) 2000-2002 convergence integrated media GmbH
(c) 2002-2004 convergence GmbH
———————————————————–
(*) DirectFB/Core: Single Application Core. (2007-08-07 19:21)
(*) Direct/Memcpy: Using MMX optimized memcpy()
(!) Direct/Util: opening ‘/dev/fb0′ and ‘/dev/fb/0′ failed
–> No such file or directory
(!) DirectFB/FBDev: Error opening framebuffer device!
(!) DirectFB/FBDev: Use ‘fbdev’ option or set FRAMEBUFFER environment variable.
(!) DirectFB/Core: Could not initialize ’system’ core!
–> Initialization error!
Could not initialize SDL – exiting
root@hells-kitchen:~# echo $FRAMEBUFFER
December 19th, 2007 at 5:51 pm
md said:
I’m not sure why it’s trying to use framebuffer instead of X. What is $DISPLAY set to?
December 23rd, 2007 at 11:33 pm
pr said:
I can start the VM with,
kvm -m 750 -no-acpi -cdrom /home/pr/kubuntu-7.10-desktop-amd64.iso -boot d gutsy-desktop.img
It’s sp slooow, what can I do to speed it up?
pr
January 15th, 2008 at 2:48 am
Robert Munn said:
Hey, great post. I have a heads up for EB and any other users that have had the /dev/fb0 problem while trying to create new VMs. I had the same issue and struggled with it for several hours. Finally, I installed Gnome (apt-get install x-window-system-core xserver-xorg gnome-desktop-environment) and I was able to create a new VM from within a Terminal window in Gnome. PITA, but at least a solution.
January 15th, 2008 at 3:39 am
Robert Munn said:
OK, out of curiosity I tried to replicate EB’s problem and was able to replicate it. The issue I found is noted as a real mode issue with Intel CPUs.
http://kvm.qumranet.com/kvmwiki/Intel_Real_Mode_Emulation_Problems
I was able to run an install using the netboot mini.iso, but it had issues with the mirror I chose.
I started a CentOS 5.1 install but it bombed trying to do the graphic install. I re-started with a text-based install of CentOS from CD. It ran fine and my CentOS VM is now running.
January 15th, 2008 at 10:53 pm
md said:
Robert, very interesting, thank you for the explanation. I was using an AMD processor that apparently does not have this issue (and hence I was stumped trying to recreate it).
February 4th, 2008 at 1:17 am
sque said:
Permission things!
After loading kvm and kvm-intel/kvm-amd it will create the device /dev/kvm (if everything went ok)
This device is accessible by root or group kvm, so add your user to kvm groop by running:
”sudo adduser $LOGNAME kvm” as previous mentioned!
If you are still getting permission denied, you probably forgot to relogin! If you want to avoid relogin run “su $LOGNAME” to create a new shell instance with new user permitions.
February 15th, 2008 at 4:12 pm
ivo said:
This is an old post, I hope you are (or somebody else is) still responding to questions. I managed to install WinXP without any problem on Ubuntu host. The problem I have is the CDROM. It works if you start the virtual machine with the CDROM already mounted, but if you try to try to insert any CD afterwards, it cannot read it, windows comes up with some error message.
For example, on situation where this is a problem is if you try to install a piece of s/w that comes on several CDs. The first CD works fine, but you cannot read other CDs.
February 15th, 2008 at 4:41 pm
ivo said:
Sorry, never mind, I found the “eject cdrom” info for qemu (with “-monitor stdio” option), I’m guessing that will work. Will try later today.
The links I found are:
http://www.free-bees.co.uk/articles/gettingstartedqemu/
and
http://calamari.reverse-dns.net:980/cgi-bin/moin.cgi/FrequentlyAskedQuestions
February 23rd, 2008 at 4:21 pm
Francois Rigaut said:
Installing mandriva with kvm on hardy:
Just a tip. In some distro, kvm comes with the -no-kvm flag disabled (e.g. in hardy heron). You sometimes need this flag to install distros, to work around some graphical bootloader issues. For instance, the mandriva liveCD will not boot into kvm without this flag.
A work around is to install Mandriva with qemu (just replace kvm by qemu in the article’s instructions). It’ll be slow, but at least it works. Remember to choose a text bootloader at the end of the installation.
Once installed, you can start you virtual mandriva normally with kvm (as mentioned in this article), and you’ll get hardware acceleration.
April 20th, 2008 at 3:01 am
Mark Harrison said:
Francois,
Thank you for that last comment (about using qemu rather than kvm during the installation only.)
The same seems to work to install some versions of Ubuntu as guests on other versions of Ubuntu.
Currently installing 6.10-server as a guest on 7.04-desktop.
April 21st, 2008 at 8:42 pm
Does VMWare Workstation 6 crash when you power on? | Rob's Blog said:
[...] I’ve added learning about KVM to my homework list. This link is a [...]
July 7th, 2008 at 2:16 pm
g’nōō-bûr » Blog Archive » Ubuntu + Compiz Rules, Vista + Aero Drools. said:
[...] of Google and Ubuntu forums, I got my dual-screens working, World of Warcraft working (on Wine), virtual machines running XP and others (for my virtual LAN–multiple VMs is why I wanted so much RAM in the [...]
December 12th, 2008 at 1:15 am
Sanjeev said:
Hello,
Such a great tutorial. Thanks a lot!!
Though I have dual core intel, but it doesn’t have support for VT-x. Does that make kvm obsolete for such machines. Will there be any difference with kvm vs qemu in such a case. Kindly take time to enlighten ;)
December 12th, 2008 at 1:59 am
md said:
A dual core Intel should have the VT extensions… are you sure it doesn’t?? What do you get when you run this?
egrep ‘(vmx|svm)’ /proc/cpuinfo
December 14th, 2008 at 12:43 am
Sanjeev said:
Thank you for the update. No, it just returned blank.
Here are the flags:
fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl est tm2 ssse3 cx16 xtpr lahf_lm
and this is the model:
Intel(R) Pentium(R) Dual CPU T2330 @ 1.60GHz
December 15th, 2008 at 12:58 pm
md said:
Interesting… I didn’t know Intel had dual core chips without VT… I don’t know what else to say, but it doesn’t look like your processor supports it.
December 26th, 2008 at 12:45 am
Jasbir said:
Please check if the BIOS has a menu for enabling /disabling virtualization
December 26th, 2008 at 6:15 pm
Mike said:
Intel(R) Pentium(R) Dual CPU T2330 @ 1.60GHz
Indicates a dual Pentium core, not “Core 2″ processor.
A “Core 2″ looks like:
Intel(R) Core(TM)2 Quad CPU Q9300 @ 2.50GHz
No sign of “Pentium” anywhere in the name. ;)
December 27th, 2008 at 4:14 pm
Dave said:
see here for framebuffer solution.
“this error is usually to do with not being allowed to run x-stuff as root, you could
sudo chmod a+rwx /dev/kvm, or whatever it is.
then run it as your non root user.”
Dave
February 24th, 2009 at 11:48 am
Nico Kadel-Garcia said:
Intrepid now provides the ‘virt-manager’ tool, written by RedHat for use with Xen and other virtual managers. This has also been backported to Gutsy, so a simple ‘apt-get install virt-manager’ should provide your readers with a very handy manager for virtual environments.
February 24th, 2009 at 11:52 am
md said:
Thanks for the update Nico!
April 27th, 2009 at 5:46 pm
Mike said:
Hey, great tutorial. I’m currently doing research on degredation caused by virtualization on Intel’s Atom architecture for my senior project and I’m having some serious problems with KVM. My goal was to have Ubuntu Gutsy desktop as the host, as well as the guest on both VMWare and KVM. It works fine on the host and VMWare but it has some wierd issues on KVM. I tried to work around the real mode issue but ended up just taking the 12 hours to install it in QEMU and making sure I back up the image right after it was done installing, just in case hehe. I have QEMU 0.10.2 installed but KVM uses its own QEMU which is still at 0.9.0 for the version of KVM I have(either 22, I think if it came w/ the distro, or 87, not really sure if its actually loading 87). I can get in most of the time but I see ata1.00 or ata2.00 errors and it tries to soft reset the hard drives. I disabled the CD(since it was having problems w/ the image for some reason) by using 3 other tiny HD images. My problem is I can’t get into Gnome. I can generally get to the terminal. I’ll try to post more details when I have sometime to look through the logs. Any ideas anyone?