Tag Archives: Install KVM on RedHat

Installing KVM on CentOS 6.4

Install CentOS 6.4

CentOS installation is the same as RedHat installation. See my previous blog on installing CentOS using  a USB stick here http://bit.ly/11dMehl.

Install KVM

Installing KVM is fairly easy, on CentOS you can use the yum groupinstall command to get all the goodies, such as below:

sudo yum groupinstall virtualization

Start libvirt with :

sudo service libvirtd start

Create network bridge if you want to use external IP and not NAT

By default KVM creates a bridge called virbr0, for NAT access from VM’s and add’s the appropriate IPtables rules in both the filter and the NAT tables. I created another bridge for public IP guests. Below are the steps you can follow to create the bridge which I named br0. Keep in mind that you can use bridge ctl utilities, however I did this manually by editing the interface config files.

$ cat /etc/sysconfig/network-scripts/ifcfg-br0

$ cat /etc/sysconfig/network-scripts/ifcfg-em1

The above will give br0 the IP of em1. Em1 is basically the BIOS name of eth0.

Enable IP forwarding

$ cat /proc/sys/net/ipv4/ip_forward
$ grep -A1 -i forwarding /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1

Download ISO image for Guest VM

wget http://mirror.stanford.edu/yum/pub/centos/6.4/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso

Use virt-install or Virtual Machine Manager to create guest VM

sudo virt-install --connect qemu:///system --name vm.example.com \
--ram 1024 --vcpus 1 --disk path=/vm1/vm.example.com.qcow2  \
--network=bridge:virbr0 --os-type=linux --os-variant=rhel6 \
--cdrom /vm1/iso/CentOS-6.4-x86_64-bin-DVD1.iso \
--graphics spice,password=mypassword --autostart

You can use virt-manager gui or virt-install which is command line based to install a VM. In terms of the network, I am using the default bridge virbr0 since the VM will have a private RFC 1918 IP, which in KVM defaults to 192.168.122.X/24 network. Specifying os-type and also os-variant allows KVM to optmize for that particular OS. Using the cdrom method I am able to specify the ISO image to install from. For connecting to the VM console, I am using spice, with the password specified on the command line. (Not secure, but there is a bug with KVM that does not allow spice connections if you specify a default spice password in /etc/libvirt/qemu.conf. The autostart option causes KVM to restart the domain when the host (hypervisor) restarts.

Use Spice or VNC to connect to console of VM and complete install

virt-viewer --connect qemu:///system  vm.example.com

External Links

  1. http://red.ht/17IX7qh
  2. http://libvirt.org/remote.html