How-To Geek

How to Install KVM and Create Virtual Machines on Ubuntu


If you’re using Linux, you don’t need VirtualBox or VMware to create virtual machines. You can use KVM – the kernel-based virtual machine – to run both Windows and Linux in virtual machines.

You can use KVM directly or with other command-line tools, but the graphical Virtual Machine Manager (Virt-Manager) application will feel most familiar to people that have used other virtual machine programs.

Installing KVM

KVM only works if your CPU has hardware virtualization support – either Intel VT-x or AMD-V. To determine whether your CPU includes these features, run the following command:

egrep -c ‘(svm|vmx)’ /proc/cpuinfo

A 0 indicates that your CPU doesn’t support hardware virtualization, while a 1 or more indicates that it does. You may still have to enable hardware virtualization support in your computer’s BIOS, even if this command returns a 1 or more.


Use the following command to install KVM and supporting packages. Virt-Manager is a graphical application for managing your virtual machines — you can use the kvm command directly, but libvirt and Virt-Manager simplify the process.

sudo apt-get install qemu-kvm libvirt-bin bridge-utils virt-manager

Only the root user and users in the libvirtd group have permission to use KVM virtual machines. Run the following command to add your user account to the libvirtd group:

sudo adduser name libvirtd


After running this command, log out and log back in. Run this command after logging back in and you should see an empty list of virtual machines. This indicates that everything is working correctly.

virsh -c qemu:///system list


Creating Virtual Machines

Once you’ve got KVM installed, the easiest way to use it is with the Virtual Machine Manager application. You’ll find it in your Dash.


Click the Create New Virtual Machine button on the toolbar and the Virtual Machine Manager will walk you through selecting an installation method, configuring your virtual machine’s virtual hardware, and installing your guest operating system of choice.


The process will by familiar if you’ve ever used VirtualBox, VMware, or another virtual machine application. You can install from a disc, ISO image, or even a network location.


To assign more than 2GB of memory to a virtual machine, you’ll need a 64-bit Linux kernel. Systems running 32-bit kernels can assign a maximum of 2 GB of RAM to a virtual machine.


By default, KVM gives you NAT-like bridged networking – your virtual machine won’t appear on the network as its own device, but it will have network access through the host operating system. If you’re running server software in your virtual machine and want it accessible from other devices on the network, you’ll have to tweak the networking settings.


After selecting your installation method, Virt-Manager will boot the guest operating system in a window. Install the guest operating system as you would on a physical machine.


Managing Virtual Machines

The Virtual Machine Manager window displays a list of your installed virtual machines. Right-click virtual machines in the window to perform actions, including starting, shutting down, cloning, or migrating them.


You can view information about the virtual machine and configure its virtual hardware by clicking the i-shaped toolbar icon in the virtual machine’s window.


Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

  • Published 06/28/12

Comments (21)

  1. Eddie santana

    Cool Thanks

  2. Gary

    Nice post… where can I create snapshots of vms?

  3. Cambo


    I’ve been looking for a simple HowTo for KVM for a while. This is extremely simple.

  4. Mr. Hills

    Thank you for this nice article. KVM is an interesting topic. But a full windows guest installation in KVM takes many hours and running very slow. Can you please show us how to do a proper windows guest installation?

  5. Paul

    I’m really enjoying the Linux features – Thanks Geek! Is there any benefit to running KVM over VirtualBox in Ubuntu? Performance?

  6. William

    As a beginner, I would like a bit of additional information. First, I need to know how to log off/log on to the terminal. Next, I encountered a minor problem when I entered
    egrep -c ‘(svm|vmx)’ /proc/cpuinfo ; the terminal display message was ‘( not recognized
    thus, I changed by backing over the ‘ sign and entered ‘ in front of the (s; same for other side. This worked. The software pkg was apparently retrieved and I was asked whether to install – answer -y. The installation proceeded, but am not sure it went to completion.

    At this point, I was stymied because you assumed that I know how to log on/off on the terminal.

    I realise this is a beginner question, and would appreciate a bit more help.

  7. Praveen

    I am already using VirtualBox (Ubuntu 12.04 as guest and host). When should I go for VirtualBox and when for KVM?

  8. dnlsrl

    @Praveen, both have the same functionality. There’s no specific case in which you should use either this software or that. KVM is just an alternative to VirtualBox or VMware.

  9. David Hughes

    Re: How to Install KVM and Create Virtual Machines on Ubuntu

    Can I do the same thing on a computer running Windows 7?

  10. Kiran


    Is that mean there is no additional benefit with KVM over Virtualbox? If that’s true then why hassle with KVM when Virtualbox is easy to install and use? anyone?

  11. Richard Steven Hack

    David Hughes: No, KVM is a Linux-only technology. You can use VirtualBox or Microsoft Virtual PC to run Linux or other versions of Windows on your Windows box.

  12. Anonymous


    Logging off/on is about as simple as it can be. The terminal has little to do with it and SUDO-ing your commands isn’t the answer either (don’t try logging out and then in again under a terminal). Chris, the author, said to log off the “system” and then back in which you would want to do if you were switching GUI environments (like switching over to GNOME, KDE, or something like that – and assuming you installed them too). To log off, look in the same area you use when you shut down. Just don’t actually choose to shut down. Look a little closer and you should be able to see an option to “log out.” Once you do you will then get to a window where you’re asked to log in by choosing (or typing in) your user name and password. Do it and you’ve completed the log out / log in procedure. (BTW, even Windows allows you to log off and in again almost exactly the same way – but most people rarely ever do.)


    As far as KVM goes, I still feel better using Virtual Box. But I may give KVM a try since it’s always good to have alternatives. I’m not sure I like VMWare since they seem all too willing to start charging money as soon as it gets a little more popular (and I have no idea what they will want if they do). Even though VMWare’s “Player” is free, it’s already pretty expensive for the full-fledged professional version which you would want/need if running “appliances” or certain customized servers. So that’s out. And Microsoft’s free “Virtual Machine” is such a joke since since it only runs on Windows and only on certain versions at that. And that’s to say nothing of Microsoft’s rather limited abilities too. Therefore, about the only real alternatives to me would be Virtual Box and now KVM. Thanks for the heads-up.

  13. Anonymous

    To anyone wondering why they’d want to use KVM,

    If you want to consistently use the same VM client across different hosts then don’t use KVM. You’re probably better off with Virtual Box or VMWare’s Player. That’s the simple answer.

    I could be wrong, but I don’t see any port of the KVM client (“app” if you prefer) for the Windows platform (where Windows is the host OS). Therefore, you may have trouble using a different guest OS created/used with KVM on a different client such as Virtual Box or VMPlayer. So if you like KVM and start using it then you’re pretty much stuck to using KVM in a Linux (Ubuntu) only environment. That may be true for KVM but probably not true as far as your guest OS’s are concerned.

    FYI: You can often (if not, always) use other guest OS’s under other clients and even under different host OS’s too. But it can all be quite a PITA to make it all work – sometimes. For example, you can take a guest OS like Windows XP that was created/used under Microsoft’s Virtual Machine and where Windows 7 was the host and use that guest (XP) with something like Virtual Box where Virtual Box is running under a host OS like OpenSuSE. (I’ve done this and it’s really pretty cool!) But for an average user this can be, and almost certainly will be quite a pain! That’s why I say stick with whatever client you decide on using – VBox, VMPlayer, KVM.

    And if running a virtual server or an “appliance” is important to you then you may want to stick exclusively with Virtual Box, mostly because it’s free. VMWare is probably even better but VMWare will charge money for advanced options/abilities particularly where virtual servers or “appliances” are concerned. (That’s probably the only reason I don’t use it.)

    As for me, I like dinking around with guest OS’s. I especially like being able to take a Windows guest that has been activated and then use it on a different physical machine. Of course, that machine will be using a VM client like Virtual Box, but it’s still quite cool. Doing this is also bending the rules quite a bit as far as Microsoft is concerned too. But it’s not exactly breaking them since I only use that one Windows license on one machine at any one time. It’s very critical to understand this if you do it too since it’s essentially a way to work around Microsoft’s “activation” bologna.

    That said, being able to (easily – ?) transport an activated Windows OS is huge to me. Imagine installing Windows and then wanting to move it to another machine. First thing you might be thinking is “where’s my imaging software?” or “where’s my installation disk?” and then maybe “what drives do I have?” and so on. But installing Windows to a virtual drive allows you to move it from machine to machine as simply as copying one huge file. You may have to do some minor tweaking to the virtualization client (like VBox) but that’s it. And if you’re guest OS happens to get compromised like catching a virus then you just delete it and copy a backup back in it’s place. I don’t think I’ll ever activate another copy of Windows on a real machine again. That is, unless I have no choice.

  14. William

    Thanks for the details wrt logging off/on; I hope to get up to speed one of these days.
    Another question has to do with the virtualization support for my computer’s BIOS, you state –

    ‘You may still have to enable hardware virtualization support in your computer’s BIOS, even if this command returns a 1 or more.’

    In my case, the number 2 was returned. However, you warn that such a number may be inadequate; how is this adequacy determined? As you can see, I am struggling along and hope to be able to master the virtualization using ubuntu.

  15. howard10

    like Ray replied I am amazed that a mother able to profit $4635 in 1 month on the computer. did you read this page N U T T Y R | C H . C O M

  16. Anonymous

    @ William

    As far as BIOS settings go, you really need to check with whoever made your motherboard. (I can’t say if that’s what howard10 was trying to say since his/her posting didn’t seem to make much sense). But to access your BIOS settings usually requires pressing the DEL key shortly after you power on. It could be some other key but typically it’s the DEL key. Once in your BIOS settings, you will want to check your CPU configuration somewhere and make sure something called “Secure Virtual Machine Mode” or something similarly worded is enabled. That’s it. Of course, if your computer is a little old then you might not have this option. As for me, I have a 1-year old Asus mobo with a AMD multi-core CPU so my system has it – yours might be different (assuming if it’s even there).

    But if I’m not mistaken, you’ve already done this and there’s really nothing more you need to do as far as the BIOS goes. About the only thing left is to try and run a guest OS and see if your host can still function without too much hesitation.

    I’ll stop here since this it really more of a discussion that should be handled in the forums. Check it out at:

    Good Luck.

  17. TheFu

    KVM vs other “desktop” VM solutions like vmplayer or virtualbox. What’s the diff?

    KVM is not the greatest/bestest solution for desktop virtualization, especially if you are new to virtualization. Use one of the other easier, close source, solutions. Be certain to install the REALLY-closed-source “guest additions” to get better graphics and HDD performance.

    OTOH, if you demand 100% F/LOSS solutions and want the most flexible virtualization solution for servers that happens to run desktops ok, then KVM with libvirt is the answer. KVM is not ideal for someone wanting to run lots of GUI desktops inside virtual machines. Spice may make that better, but right now, it isn’t ready.

    Why not Xen? Xen requires changes to both the hostOS kernel AND the clientOS kernels. That is unacceptable. I’ve been running Xen VMs for about 4 yrs. About twice a year, a new kernel update makes the system unstable or it refuses to boot at all. This is the danger of using any virtualization that isn’t part of the core Linux kernel. Besides that issue, Xen has been very stable and Xen paravirtual VMs perform well.

    Why not VirtualBox? VirtualBox is an impressive tool, but it is sponsored by Oracle, which means it is likely to be “monetized” sooner than later, and the guest extensions are not F/LOSS. Performance is pretty great for a HVM solution. On Windows hosts, Vbox is stable and running 1 or 2 VMs does work. I’ve been completely unimpressed with stability on Linux Server hosts, but that is probably a local issue. The same hardware ran ESXi and KVM without any stability issues, however. To use remote access for the VMs, the proprietary version of virtualbox was required. That broke my F/LOSS mandate.

    I haven’t tried VMware vmplayer in many years, so I can’t comment on anything other than to say it is not F/LOSS and Vmware is trying to monetize everything they can. VMware Workstation is the commercial version of this tool with lots of extras that a QA and software development department can make lots of use with. If you are in QA, you **need** to be using VM solutions.

    What about ESX and ESXi? VMware has also decided to monetize all use of their server-centric hypervisors … er … heavily. Further, to use either, you **must** have an MS-Windows OS installed somewhere to run the vSphere management software. To many people, like me, that is completely unacceptable. I’ve run ESX and ESXi both internally and for clients. It is rock solid. There are thousands of commercial solutions for both. Performance is pretty great for a HVM solution. Costs are pretty high compared to other solutions, but it works and it scales for the enterprise needing 20-10,000 physical servers running 4-50 VMs each.

    USB support – this is worth a mention. I’ve used USB passthru under VirtualBox and it works … mostly. I’ve never attempted any USB passthru with the other VM solutions, but I suspect that vmplayer would work easily. I think KVM needs newer Xeon CPUs and probably some PCI capabilities for this to work, but I don’t know for sure – VT-d is the term.

    Performance that I’ve seen between KVM, Xen, and ESXi on identical hardware is pretty good on all. Different workloads do better on each and both KVM and Xen support lite-er paravirtual or “container” based solutions. ESXi does not. Xen was a great first step 8 yrs ago. Amazon’s EC2 is based on Xen, so it can’t be all bad. KVM is where all the new kids are developing today – KVM is backed by NASA, Redhat, Canonical, and all the other Linux big players. Microsoft is providing patches to make Windows clientOSes run better under KVM too.

    In Summary:
    * If you mainly want to run a single Windows Desktop inside a VM, use VirtualBox.
    * If you mainly want to run mostly Windows Servers inside VMs, use ESXi. You can run Linux too, no problem. ESXi is fairly picky about hardware, however.
    * If you mainly want to run mostly Linux Servers inside VMs, use KVM. You can run Windows too. I actually run a Windows7 Media Center inside a KVM VM to record QAM TV and it works fine, but there’s no way to get video playback from the VM. The remote graphics of KVM simply aren’t that good.

    There you have it, a summary for which virtualization would be best for most people.

  18. David

    Just went through this same setup today… then read it here… have been using Proxmox across 6 low end servers at work and just started to entertain running VM on my desktop.

  19. SMed79

    Thank you g33k :) nice post!

  20. ktate

    Trying to create a new VM and getting this error message:

    Unable to complete install: ‘internal error Process exited while reading console log output: char device redirected to /dev/pts/1
    qemu-kvm: -drive file=/var/lib/libvirt/images/,if=none,id=drive-virtio-disk0,format=raw,cache=none: could not open disk image /var/lib/libvirt/images/ Permission denied

  21. Kesco

    Thanks. The blog help me a lot.

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!