Xen is a virtual machine monitor that supports execution of multiple guest operating systems with unprecedented levels of performance and resource isolation.
Here are the steps to install Xen on CentOS:
1. Execute the following commands to install Xen and Xen kernel.
[root@localhost ~]#yum install kernel-xen xen
Installing: xen-libs ######################### [1/9]
Installing: kernel-xen ######################### [2/9]
Installing: dnsmasq ######################### [3/9]
Installing: libvirt ######################### [4/9]
Installing: libvirt-python ######################### [5/9]
Installing: python-virtinst ######################### [6/9]
Updating : util-linux ######################### [7/9]
Installing: xen ######################### [8/9]
Cleanup : util-linux ######################### [9/9]
Installed: kernel-xen.i686 0:2.6.18-128.1.10.el5 xen.i386 0:3.0.3-80.el5_3.2
Dependency Installed: dnsmasq.i386 0:2.48-1.el5.rf libvirt.i386 0:0.3.3-14.el5_3.1 libvirt-python.i386 0:0.3.3-14.el5_3.1 python-virtinst.noarch 0:0.300.2-12.el5 xen-libs.i386 0:3.0.3-80.el5_3.2
Dependency Updated: util-linux.i386 0:2.13-0.50.el5
Complete!
2. Once the installation is over, you will find the new kernel “Xen kernel (vmlinuz-2.6.18-8.1.4.el5xen)” in the grub.conf file.
[root@localhost xinetd.d]#cat /etc/grub.conf
default=1
timeout=5
splashimage=(hd0,7)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-128.1.10.el5xen)
root (hd0,7)
kernel /xen.gz-2.6.18-128.1.10.el5
module /vmlinuz-2.6.18-128.1.10.el5xen ro root=LABEL=/1 rhgb quiet
module /initrd-2.6.18-128.1.10.el5xen.img
title Linux (2.6.18-8.el5)
root (hd0,7)
kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/1 rhgb quiet
initrd /initrd-2.6.18-8.el5.img
title windows
rootnoverify (hd0,0)
chainloader +1
3. Change the default value to 0 in the file ‘/etc/grub.conf’
default=0
4. Create an nfs mount /root/install and copy the contents of the CentOS DVD contents to /root/install directory.
[root@localhost ~]#mkdir /root/install
[root@localhost ~]#mount /dev/cdrom /mnt/cd
[root@localhost ~]#cp -prf /mnt/cd/* /root/install
[root@localhost ~]# vi /etc/exports/root/install *(rw,sync)
[root@localhost ~]# exportfs -a
5. Create a new directory for a virtual machine “/vm” and reboot the server.
6. Once you reboot the machine, the system will now have the new Xen kernel.
[root@localhost opt]# uname -a
Linux localhost.localdomain 2.6.18-128.1.10.el5xen #1 SMP Thu May 7 11:51:15 EDT 2009 i686 i686 i386 GNU/Linux
7. To check if Xen has started, execute the command :
[root@localhost ~]# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 736 2 r—– 300.4
8. You can use the tool “virt-install” for creating virtual machines as follows :
[root@localhost ~]#virt-install
It will come up with a few questions such as :
What is the name of your virtual machine?
vm01How much RAM should be allocated (in megabytes)
256What would you like to use as the disk (path)?
/vm/vm01.imgHow large would you like the disk (/vm/vm01.img) to be (in gigabytes)?
5Would you like to enable graphics support? (yes or no)
noWhat is the install location?
/root/install ( This is the nfs mount)
9. This would create the vm01 configuration file /etc/xen/vm01 for us (in dom0).
It should look like this:
[root@localhost ~]#vi /etc/xen/vm01
name = “vm01”
uuid = “219eaf21-e688-611f-53ac-f28f44dd73e3”
maxmem = 256
memory = 256
vcpus = 1
bootloader = “/usr/bin/pygrub”
on_poweroff = “destroy”
on_reboot = “restart”
on_crash = “restart”
vfb = [ ]
disk = [ “tap:aio:/vm/vm01,xvda,w” ]
vif = [ “mac=00:16:3e:6d:88:1e,bridge=xenbr0” ]
10. To log in to the virtual machine, use the following command:-
[root@localhost ~]#xm console vm01
That’s it !
Some important Xen commands:
1. xm create -c /path/to/config
This command is used to start a virtual machine
For example, xm create /etc/xen/vm01
2. xm shutdown
Command to stop a virtual machine
For example, xm shutdown vm01
3. xm destroy
Stop a virtual machine immediately without shutting it down
For example, xm destroy vm01
4. xm list
List all running systems
5. xm console
Log in on a virtual machine
For example, xm console vm01
7. xm help
List of all commands