Install & Configure KVM Virtualization On CentOS 6.X / RHEL 6.X
KVM stands for Kernel Based Virtual Machine. KVM is a Linux kernel module that allows a user space program access to the hardware virtualization features of Intel and AMD processors. With the KVM kernel module, VMs run as ordinary user-space processes. KVM uses QEMU for I/O hardware emulation. QEMU is a user-space emulator that can emulate a variety of guest processors on host processors with decent performance. Using the KVM kernel module allows it to approach native speeds.
KVM is managed via the libvirt API and tools. Some libvirt tools used in this article include virsh , virt-install and virt-clone . Some of common Terms we will using this document is :
- Host – The hypervisor or physical server where all VMs are installed.
- VMs (Virtual Machines) – Virtual servers that are installed on top of a physical server
In this post we will discuss how to install & configure KVM based virtualization step by step in CentOS 6.X / RHEL 6.X . I am assuming we have hypervisor with good configuration and CentOS / RHEL is installed on top of this.
Step:1 Verify Virtualization Technology (VT) is enabled in your server’s BIOS.
# grep -E 'svm|vmx' /proc/cpuinfo vmx is for Intel processors svm is for AMD processors
If VT is not enabled , then reboot the your server , go BIOS setting & enable it
Step:2 Install the required Packages using yum
# yum install kvm python-virtinst libvirt libvirt-python virt-manager virt-viewer libguestfs-tools bridge-utils
Verify the following kernel modules are loaded, and if not load manually:
# lsmod | grep kvm
To load the KVM module use below commands :
# modprobe kvm # modprobe kvm_intel (only on Intel-based systems)
Step:3 Set the Networking on Hypervisor for KVM
In my case my server has only one lan interface, so i will bind the Ethernet (eth0) to bride interface (br0). Bridge interface is required to access the Virtual machine outside of hypervisor. Follow the below steps to create bridge “br0”.
# cd /etc/sysconfig/network-scripts # cp ifcfg-eth0 ifcfg-br0 # vi ifcfg-br0 DEVICE= br0 BOOTPROTO=none HWADDR=00:22:68:5e:34:06 ONBOOT=yes IPADDR=10.0.0.30 NETMASK=255.255.255.0 GATEWAY=10.0.0.1 TYPE= Bridge # vi ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none HWADDR=00:22:68:5e:34:06 ONBOOT=yes TYPE=Ethernet BRIDGE=br0
Just replace the ip address according to your setup.
Step:4 Start the networking & libvirt services
# chkconfig NetworkManager off ; service NetworkManager stop # service network restart ; chkconfig network on # service libvirtd start ; chkconfig libvirtd on
Note: KVM creates image files (which look just like regular files in the file system) for each VM and assumes you are going to place them in directory /var/lib/libvirt/images. If you don’t like to use /var/lib/libvirt/images. then create a separate partition for VM images, like /vm-images.
Step:5 Now create a virtual Machine using virt-manager .
(5.1) Open the terminal Type virt-manager
Click on Create a new Virtual Machine
(5.2) when we click on Forward , it will ask for ISO file , so select the respective ISO file , in my i am selecting Ubuntu Server 12.10
(5.3) Now Specify the RAM and CPU / Cores , as shown below
(5.4) Specify the Disk size for the virtual machine , by default a image will be created under /var/lib/libvirt/images , if you want to change the location the other option ‘Select managed or existing storage’
Click on Forward
(5.5) Click on Advance options , Select Bridge br0 and Click on Finish
(5.6) Installation of Ubuntu Server 12.10 using KVM virtualization has Started as shown below :
Step:6 Once the installation is finish then access the Virtual Machine via virt-manager
Double Click on “nextstep” , below screen will appear , login to the machine and configure the network settings in the machine and then try to access the VM from the network. This concludes the tutorial and enjoy the KVM based virtualization 🙂