Virtualization has many uses. You can use it to test another operating system, run applications that your OS does not support, or even maintain virtual servers within one or more virtual machines.
KVM (kernel-based virtual machine) is a Linux virtualization tool that makes use of hardware-assisted virtualization (also called native virtualization) using processor technology such as Intel VT-x and AMD-V. Red Hat’s Virtual Machine Manager now has support for KVM, making it easy to setup a virtual machine with a free graphical interface. It is also available for Fedora, Gentoo, FreeBSD, Ubuntu, and many other operating systems.
Installation will vary according to the operating system, but we will look at the Ubuntu installation to get an idea of what it entails. Since KVM requires hardware virtualization capabilities, you need to make sure your computer’s processor supports it.
Open a terminal and type this command:
The output will either be a “0” or a “1”. A “0” unfortunately means that you do not have hardware virtualization. If you get a “1” and have virtualization enabled in your BIOS, you are good to go. Without hardware virtualization, you cannot use KVM extensions. You can still run virtual machines, but they will be painfully slow, as I discovered on my laptop with an old Intel T4200 processor.
If you want to double check the results, you can also run this command:
If all goes well, it will return:
Ubuntu has some meta-packages you can install to get the virtualization tools you need. With one command, you can install most of them:
If you want to install each package manually, see the Ubuntu documentation. After the installation, you should have qemu-kvm and virt-manager (the graphical frontend) installed.
After installation, you need to make sure KVM is configured and given the necessary permissions. Type this command:
Among your user groups, you should see “kvm” and “libvirtd”. If either or both are missing, you can run these commands to add your local user to the groups:
The last post-installation step you need to take is to logout and log back in. If you do not, you will get a qemu error like this: “libvir: Remote error : Permission denied”
Create a Virtual Machine
Once you are logged back in, you can start Virtual Machine Manager. It should be in your applications menu. Alternatively, press Alt+F2 and type virt-manager.
On the first run, there will only be one available button to click labeled “Create a new virtual machine”. Click it and go through the creation process.
- Name the virtual machine. It can be pretty much anything. It is only an identifier for you to remember what it is.
- Choose the installation method. In this example, I am going to use a CentOS 6 LiveCD ISO. That requires the first option “Local install media”. After choosing, click “Forward”.
- Select the OS type and version. In my example, I chose “Linux” and “Red Hat Enterprise Linux 6”.
- Select the amount of RAM you want to allocate and the number of CPUs to use.
- Set your virtual disk size. This largely depends on the OS you are using and the amount of space you think you will need.
- Set your network options. In most cases, the right option is already selected.
- Click Finish
Virtual Machine Manager should immediately start booting your virtual machine. If you booted from an ISO, you can then install the OS as you normally would or even run it from the LiveCD. If you want to see real-time information about your virtual hardware, click the “show hardware virtualization details” button. You do not have to keep the virtualization window open to keep running your virtual machine. This is useful if you only intend to connect to it remotely and use it as a server.