This post discusses about creating virtual machine using KVM, virt-install and virt-manager. So, here is a step by step process from installing necessary stuff to running your favourite os in virtual machine. I am assuming that you are running Ubuntu.
Step-1 :- Checking hardware virtualization
1. Check if your processor supports hardware virtualization or not.
egrep -c '(vmx|svm)' /proc/cpuinfo
If output of above command is 0 then your CPU doesn’t support hardware virtualization and if output is 1 or more then it does. But you still need to check in your BIOS id virtualization [VT-x in intel and AMD-v in AMD processor] is enabled or not.
2. You can also execute following command to check for kvm compatibility:
Ouput of this command should be like following:
INFO: /dev/kvm exists
KVM acceleration can be used
If you see, something like following then you can still run virtual machines, but it’ll be much slower without kvm extensions.
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
But if you see, something like following then check your kernel version. KVM works with Ubuntu-kernel only. So, if you are running vanilla kernel then there may be an issue. Either you need to download Ubuntu-kernel image or you can go for using kernel version which comes by default with particular Ubuntu version. For example, Ubuntu 14.04 comes with 3.13.0-24-generic.
INFO: /dev/kvm does not exist
HINT: sudo modprobe kvm_intel modprobe
FATAL: Module msr not found.
Step-2 :- Installation of kvm
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
2. Add your username to the group libvirtd
sudo adduser `id -un` libvirtd
After running above command reboot in your system to add your username effectively in libvirtd group. I repeat do not just relogin into your system, please reboot.
Step-3 :- Verifying installation
You can verify your installation using following command:
virsh -c qemu:///system list
This should give output like this:
Id Name State
If this command fails to connect with hypervisor, then you can check the errors and the solutions here.
Step-4 :- Restart kernel modules
modprobe -a kvm
Step-5 :- Install virt-viewer
You can install virt-viewer for viewing instances:
sudo apt-get install virt-viewer
Step-6 :- Install virt-manager
This is optional. Virt-manager is a GUI application for creating and managing virtual machines. You can install it either from Ubuntu software center or using following command:
sudo apt-get install virt-manager
Step-7 :- Creating virtual machine
You can either use following command for creating virtual machines or go for this link if you want to create it using virt-manager.
virt-install --name=guest_name --arch=x86_64 --vcpus=1 --cdrom=/var/lib/libvirt/image/ubuntu-12.04.5-desktop-amd64.iso --disk path=/mnt/virtual_machines/guest_name.img,size=20
Virt-install is written using Libvirt API. It is very interesting to learn how all things are binded together. In case someone is interested, then go for cloning repo or can browse online here. Also, in the command above I just gave values to options which are mandatory. One can check other options too.
So, this is complete process of creating virtual machine using KVM and libvirt. I will write some other posts about libvirt as I am learning it these days along with my internship.