Monthly Archives: April 2014
Xen Virtualization in Centos 6
Xen virtualization steps are given below.
1. Make sure that SELinux is disabled or permissive.
vi /etc/sysconfig/selinux
and set “SELINUX=disabled”. Then reboot server.
2. 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
=========
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:
vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0" NM_CONTROLLED="yes" ONBOOT=yes TYPE=Bridge BOOTPROTO=none IPADDR=192.168.0.100 PREFIX=24 GATEWAY=192.168.0.1 DNS1=8.8.8.8 DNS2=8.8.4.4 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System br0" Modify /etc/sysconfig/network-scripts/ifcfg-eth0 as follows (comment out BOOTPROTO, IPADDR, PREFIX, GATEWAY, DNS1, and DNS2 and add BRIDGE=br0): vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0" NM_CONTROLLED="yes" ONBOOT=yes HWADDR=00:1E:90:F3:F0:02 TYPE=Ethernet #BOOTPROTO=none #IPADDR=192.168.0.100 #PREFIX=24 #GATEWAY=192.168.0.1 #DNS1=8.8.8.8 #DNS2=8.8.4.4 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System eth0" UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 BRIDGE=br0 Restart the network: /etc/init.d/network restart and run "ifconfig", it should network bridge. [root@server1 ~]# ifconfig br0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02 inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:17 errors:0 dropped:0 overruns:0 frame:0 TX packets:29 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1196 (1.1 KiB) TX bytes:2794 (2.7 KiB) eth0 Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02 inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4554 errors:0 dropped:0 overruns:0 frame:0 TX packets:3020 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6249612 (5.9 MiB) TX bytes:254928 (248.9 KiB) Interrupt:25 Base address:0x6000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:3 errors:0 dropped:0 overruns:0 frame:0 TX packets:3 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1304 (1.2 KiB) TX bytes:1304 (1.2 KiB) 3. Installing XEN: First check if your CPU supports hardware virtualization - if this is the case, the command egrep '(vmx|svm)' --color=always /proc/cpuinfo
should display something, e.g. like this:
[root@server1 ~]# egrep ‘(vmx|svm)’ –color=always /proc/cpuinfo
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
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
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse
[root@server1 ~]#
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
yum install http://au1.mirror.crc.id.au/repo/kernel-xen-release-6-3.noarch.rpm
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:
vi /boot/grub/menu.lst
The first listed kernel should be the Xen kernel that you’ve just installed:
[...]
title CentOS (2.6.32.54-1.el6xen.x86_64)
root (hd0,0)
kernel /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
initrd /initramfs-2.6.32.54-1.el6xen.x86_64.img
[...]
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 fordom0_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
[...]
Change the value of default to 0 (so that the first kernel (the Xen kernel) will be booted by default):
[...] default=0 [...] 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
initrd /initramfs-2.6.32-220.el6.x86_64.img
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:
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:
yum groupinstall 'Development Tools'
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
Now reboot machine to load new kernel
The system should now automatically boot the new Xen kernel. After the system has booted, we can check that by running
uname -r
[root@server1 ~]# uname -r
2.6.32.54-1.el6xen.x86_64
[root@server1 ~]#
So it’s really using the new Xen kernel!
a. xm list
b. to check if Xen has started. It should list Domain-0 (dom0):
[root@server1 ~]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 1 r—– 18.9
[root@server1 ~]#
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.
virsh list
should show this:
[root@server1 ~]# virsh list
Id Name State
———————————-
0 Domain-0 running
[root@server1 ~]#
4. Paravirtualization:
CentOS has a nice tool called virt-install with which we can create virtual machines for Xen. To start it, we simply run
virt-install –prompt –network bridge=br0 –virt-type=xen
The tools asks a few questions before it creates a virtual machine. I want to call my first virtual machine vm01, with 1024MB RAM and a disk size of 10GB. I want to store it in the file /var/lib/libvirt/images/vm01.img:
Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems.
<– no
What is the name of your virtual machine?
<– vm01
How much RAM should be allocated (in megabytes)?
<– 1024
What would you like to use as the disk (file path)?
<– /var/lib/libvirt/images/vm01.img
How large would you like the disk (/vm/vm01.img) to be (in gigabytes)?
<– 10
What is the install URL?
<– http://ftp.tu-chemnitz.de/pub/linux/centos/6.2/os/x86_64
Regards,
Jeen