Friday, October 26, 2012


Virtualization With Xen On CentOS 6.2 (x86_64) (Paravirtualization)

Step1:
Make sure that SELinux is disabled or permissive:



cmd: vi /etc/sysconfig/selinux


Step2:
If you had to modify /etc/sysconfig/selinux, please reboot the system:



reboot



Step3:Creating A Network Bridge

We need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network.
To do this, we install the package bridge-utils...
cmd: yum install bridge-utils
... and configure a bridge. Create the file /etc/sysconfig/network-scripts/ifcfg-br0 (please use the IPADDR, PREFIX, GATEWAY, DNS1 and DNS2 values from the /etc/sysconfig/network-scripts/ifcfg-eth0 file); make sure you use TYPE=Bridge, not TYPE=Ethernet:
cmd: vi /etc/sysconfig/network-scripts/ifcfg-br0




Modify /etc/sysconfig/network-scripts/ifcfg-eth0 as follows

cmd: vi /etc/sysconfig/network-scripts/ifcfg-eth0


Restart the network...



cmd: /etc/init.d/network restart



... and run



cmd: ifconfig




Step 4: Installing Xen

First check if your CPU supports hardware virtualization - if this is the case, the command


cmd: egrep '(vmx|svm)' --color=always /proc/cpuinfo

egrep'(vmx|svm)'--color=always/proc/cpuinfo
flags:fpuv medepsets cmsrpaem cecx8apicsepmtrrpgemcacmovpatpse3clflushmmxfxsrssesse2 ht syscall
 nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall



If nothing is displayed, then your processor doesn't support hardware virtualization. This means you can use only paravirtualization with Xen, but not hardware virtualization.
As CentOS 6 is based on RedHat 6, and RedHat has dropped support for Xen in version 6, we need to get Xen from a third-party repository. We can enable the repo as follows:
yum install wget
cd /etc/yum.repos.d/
wget http://www.crc.id.au/repo/kernel-xen.repo

To install Xen, we now simply run
cmd: yum install kernel-xen xen
This installs Xen and a Xen kernel on our CentOS system.
Before we can boot the system with the Xen kernel, please check your GRUB bootloader configuration. We open /boot/grub/menu.lst:
cmd: vi /boot/grub/menu.lst
We need to modify that section so that the Xen hypervisor gets loaded first. In the kernel /vmlinuz... line, replace the first word kernel with module. Do the same in the next line - replace the first word initrd with module in the initrd /initramfs... line. Then add the line kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=1 dom0_vcpus_pin after the root line and before the first module line (if you have more than one CPU core, you can specify another number than 1 for dom0_max_vcpus). The final kernel section should look like this:

[...]
title CentOS (2.6.32.54-1.el6xen.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=1 dom0_vcpus_pin
        module /vmlinuz-2.6.32.54-1.el6xen.x86_64 ro root=/dev/mapper/VolGroup00-LogVol00 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=de rd_LVM_LV=VolGroup00/LogVol01 rd_LVM_LV=VolGroup00/LogVol00 rd_NO_DM
        module /initramfs-2.6.32.54-1.el6xen.x86_64.img
[...]
The complete /boot/grub/menu.lst should look something like this:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/VolGroup00-LogVol00
#          initrd /initrd-[generic-]version.img
#boot=/dev/sde
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32.54-1.el6xen.x86_64)
        root (hd0,0)
        kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=1 dom0_vcpus_pin
        module /vmlinuz-2.6.32.54-1.el6xen.x86_64 ro root=/dev/mapper/VolGroup00-LogVol00 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=de rd_LVM_LV=VolGroup00/LogVol01 rd_LVM_LV=VolGroup00/LogVol00 rd_NO_DM
        module /initramfs-2.6.32.54-1.el6xen.x86_64.img
title CentOS (2.6.32-220.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/VolGroup00-LogVol00 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=de rd_LVM_LV=VolGroup00/LogVol01 rd_LVM_LV=VolGroup00/LogVol00 rd_NO_DM

Before we reboot, we install the libvirt and python-virtinst (which contains the virt-install tool which we will use later on to install Xen VMs) packages:
cmd: yum install libvirt python-virtinst

Because the libvirt package from CentOS 6/RedHat 6 has no support for Xen, we must rebuild it with Xen support. To do this, we install a few prerequisites now:
cmd: yum groupinstall 'Development Tools'
OR



cmd: yum install python-devel xen-devel libxml2-devel xhtml1-dtds readline-devel ncurses-devel libtasn1-devel gnutls-devel augeas libudev-devel libpciaccess-devel yajl-devel sanlock-devel libpcap-devel libnl-devel avahi-devel libselinux-devel cyrus-sasl-devel parted-devel device-mapper-devel numactl-devel libcap-ng-devel netcf-devel libcurl-devel audit-libs-devel systemtap-sdt-devel



Let's find out our libvirt version:
cmd: rpm -qa | grep libvirt






It's 0.9.4, so we download the appropriate src.rpm package into /root/src and install it:

cmd: mkdir /root/src
cmd : cd /root/src
cmd: wget http://vault.centos.org/6.2/os/Source/SPackages/libvirt-0.9.4-23.el6.src.rpm
cmd: rpm -i libvirt-0.9.4-23.el6.src.rpm




The last command will show some warnings that you can ignore:
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
Next we patch Xen support into the libvirt sources:

cmd: wget http://pasik.reaktio.net/xen/patches/libvirt-spec-rhel6-enable-xen.patch
cmd: cd /root/rpmbuild/SPECS
cmd: cp -a libvirt.spec libvirt.spec.orig
cmd: patch -p0 < ~/src/libvirt-spec-rhel6-enable-xen.patch


Now we build a new libvirt package:

cmd: rpmbuild -bb libvirt.spec

At the end of the build process you should see something like this:
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-client-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-devel-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-lock-sanlock-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-python-0.9.4-23.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-debuginfo-0.9.4-23.el6.x86_64.rpm
Go to the directory where the new packages have been created (/root/rpmbuild/RPMS/x86_64/ in this case)...



Cmd: cd /root/rpmbuild/RPMS/x86_64/



... and install the new libvirt packages (with Xen support) as follows:
cmd: rpm -Uvh --force libvirt-0.9.4-23.el6.x86_64.rpm libvirt-client-0.9.4-23.el6.x86_64.rpm libvirt-python-0.9.4-23.el6.x86_64.rpm

Afterwards, we reboot the system:
cmd: reboot
The system should now automatically boot the new Xen kernel. After the system has booted, we can check that by running
cmd: uname -r






So it's really using the new Xen kernel!
We can now run
cmd: xm list





Instead of using the xm command, I will from now on use the virsh command to manage Xen VMs. This is the preferred way as we are using libvirt.



Cmd: virsh list
should show this:



Installing Centos as a Guest Operating System on Xen

Step1:
Go to Application -> System Tools -> Virtual Machine Manager
Its asking Root Password


Right Click on loachost(Xen) and the click on New


Its a ParaVirtualization It does not Give full Options
So we can install os by using Network Install(HTTP,FTP,NFS)








Its Creating Virtual Machine

























In this way we can install Centos ...






PLEASE REFER BELOW LINK FOR FULL REFERENCE

http://www.howtoforge.com/virtualization-with-xen-on-centos-6.2-x86_64-paravirtualization-and-hardware-virtualization

No comments:

Post a Comment