Showing posts with label Xen. Show all posts
Showing posts with label Xen. Show all posts

Wednesday, September 14, 2011

Full virtualization using XEN


Virtualization is a technique of dividing a single server into several Virtual Servers, according to hardware and/or software, CPU Time/Process scheduling and memory allocation. Users can install and use their own Operating Systems simultaneously on these virtual servers.
Simply put, it is a server that runs different guest Operating Systems like RedHat Linux, FreeBSD, Debian, Microsoft Windows XP…etc at the same time, controlled by the Host Operating system. Users feel they are using their individual servers with the Operating System they wish to use.

Host OS - The base operating system which controls and co-ordinates the Virtual Servers
Guest OS - The Operating System installed on a Virtual Server

Types of Virtualization

The most commonly using virtualization techniques are;

1. Operating system-level virtualization

This is the simple and most popular virtualization technique. In this method, the virtualization is performed based on a single host operating system. Only the same instance of the host Operating System can be used on the virtual Servers as guest Operating Systems.
Examples : OpenVZ, Linux-VServer

2. Paravirtualization

This technique is somewhat similar to OS level Virtualization, except it is possible to use different guest Operating Systems like Microsoft XP, RedHat Linux, SUSE…etc on the virtual servers. This requires customized versions of Operating systems as guest operating systems. i.e, we can’t use the currently available XP, FC6…etc on these virtual servers, but the specially designed versions of these operating systems.
Many OS vendors have started selling their modified versions to perform Paravirtualization.
Examples : XEN, UML
hypervisor - The hypervisor is an application (eg. Kernel, Host OS) that runs between the server hardware and the guest operating systems. In the case of XEN, a specially designed Linux kernel is the hypervisor.

3. Full virtualization

This is the ideal virtualization technique in which any Operating system is used as the host OS and guest OSs. i.e, we can use unmodified versions of OSs on the virtual servers.
Examples : XEN, Vmware, z/VM

Full virtualization using XEN

Actually XEN lies between paravirtualization and full virtualization. XEN integrates its hypervisor on a linux kernal, so that we have to compile and run this modified kernel on the server on which we wish to perform the virtualization. XEN also supports virtual servers management though graphical interfaces. Therefore it is better to install a full version of Linux on the server first, then compile xen-linux kernel, reboot the server using the xen-linux kernel to create and manage servers. In this case, we can create and manage virtual servers through console and/or GUI oriented applications.

Implementing Full Virtualization using XEN (Simplified Steps)

  1. Requirements
  2. CPU support
    Installing XEN
    Enabling XEN Kernel
    Installing Windows 2003 on top of a Virtual Machine
    Installing Linux based OSs on top of a Virtual Machine

Requirements

The requirement of a XEN Fully Vitualized server are as follows;
  1. A server installed with working Fedora 7 Operating System
  2. Application builders like gcc v3.2.x binutils, GNU make
  3. 1 GB Memory (Recommending 256 M for each virtual servers) 40 GB HDD
  4. A VT enabled Intel system or AMD-V enabled AMD system (For Full Vitualization)
  5. CDROMs of Guest Operating Systems (Linux OSs or Windows OSs like 2003/XP/Vista)

CPU Support

Make sure that the CPU supports Full virtualization over XEN.
  1. For INTEL Systems, it should have the ‘vmx’ support. To check, use the following command;# grep vmx /proc/cpuinfo
  2. For AMD systems, it should have ’svm’ support. To check, use the following command;# grep svm /proc/cpuinfo
    If these commands return nothing, then check whether the setting related to ‘Virtualization’ has enabled on the BIOS (it is turned OFF by default). If the BIOS is not enabled for virtualization, then it may be necessary to upgrade the BIOS.

Installing XEN

First, check for a XEN enabled kernel on the Host OS. Installation of a XEN kernel on Fedora 7 is quite simple using the ‘yum’ command as follows;
# yum install kernel-xen xen virt-manager
This will install,
  1. XEN enabled kernel for both Host and Guest OSs
  2. All required packages and their dependencies
  3. Hypervisor for controlling Guest OSs
  4. XEN packages for interacting with the Hypervisor

Enabling XEN Kernel

  1. Edit the file ‘/boot/grub/grub.conf’ and set the default kernel to ‘kernel-xen’
  2. Restart the server
  3. Type the command ‘uname -r’ and make sure that the running kernel is ‘kernel-xen’

Installing Windows 2003 on top of a Virtual Machine

Not so long ago, installing any OS (whether it is Linux or Windows) on top of XEN was quite a nightmare for system administrators. Now Fedora 7 provides a way to install Guest OSs in a few mouse clicks. Here is how to do it.
  1. Log into Fedora 7 (Host OS) in X session
  2. Goto Application menu and select ‘Virtual Machine Manager’ from ‘System Tools’
  3. This will show the wizard to cerate/manage Virtual Machines
  4. Select the ‘New Machine’ option from the ‘File menu’
  5. Type a name for the new node, say ‘Windows2003′ (make sure there are no spaces on the node name), and click on the ‘Forward button’.
  6. On the next window select ‘Full Virtualization’ and click on the ‘Forward button’.
  7. Now locate the installation media, you can either use a CD-ROM or use an ISO image
  8. Also select the type of Guest OS as ‘Windows 2003′
  9. Assign a storage space for the Virtual Machine
  10. Now select ‘default virtual network’ and click on the ‘Forward button’.
  11. Now allocate memory and CPU for the new Virtual Machine (A minimum of 250 M of RAM and 1 VCPU)
  12. Now the installation of Windows 2003 oven XEN will begin
  13. Once the installation is completed, we can start using the Windows 2003 installed Virtual Machine.

Installing Linux based OSs on top of a Virtual Machine

Use the same steps described in the previous section, using proper CD-ROM or ISO image.

Comments

If you wish to create Virtual Machines using a bash shell, use the following command.
# /usr/sbin/virt-install
This method will not allow you to directly install the OS from a CD_ROM or from an ISO image, but it can from NFS, FTP, and HTTP locations. A detailed procedure for doing this can be found at xensource.

References

  1. http://www.xensource.com
  2. http://librenix.com/?page=Xen
  3. http://fedoraproject.org
  4. http://www.cl.cam.ac.uk/research/srg/netos/xen/

Business Plan for Xen Virtualization


A review of the Web Hosting industry shows that Virtualization is the rage these days. The ability to collapse computing resources into abstraction layers enables greater flexibility and storage. This article introduces Xen Virtual Private Server(VPS), advantages, comparison to similar technologies and primarily why we should choose Xen Technology.

1.1 Case Study

When we thought of implementing VPS on our test Workstation, we had the following requirements on mind:-
1. Ease of use ( Remember this is not for a newbie into Hosting).
2. Should be able to employ multiple servers on the same machine.
3. Each server should be of a different type(capable of handling different OS versions).
4. Cost factor.
5. Increased performance and isolation of storage.

1.2 Why not a dedicated server?

How can we make hosting more profitable? Our test workstation had a single server with Intel Pentium Dual Core Processor, with 2GB of Ram , 80 GB Hard Disk. A dedicated server of the same configuration would cost us a minimum of $150 to $170. Understanding the real potential of VPS, we realized that we could implement four VPS nodes on the same server, producing a decent performance, with each node costing a maximum of $15 to $20. We decided to go ahead with Virtualization. What was left was the choice of technology to be used for implementation.

2. Virtual Private Servers

Virtual Private Servers are the most advanced step in server virtualization technology. They are used to partition a single physical server into many isolated virtual private servers. Each virtual private server looks and behaves exactly like a real networked server system, complete with its own set of init scripts, users, processes, file systems, etc.
Advantages of VPS Hosting :-
* High Availability
* Customer Self - Management
* Managed Infrastructure
* Fast Deployment
* Dedicated Resources (CPU, RAM)
* Dedicated Performance
* Fast and Painless Migration from existing hosting environment
* Upgrading Processor Speed, RAM and HDD
The choice of VPS client was something to think about. Our choice was Xen, the reasons for which is discussed briefly on the forth coming pages.

3. Xen

Xen is a high performance and secure open source virtualization framework. Xen implements virtualization by inserting a software layer-hypervisor between the hardware and the Operating system. This in turn enables the server to run multiple virtual servers. The hypervisor acts as an abstraction layer in between the hardware and the Operating system. The main advantage is that Xen can execute multiple virtual machines, each running a different OS ,on a single system with relatively close and reliable performance.
We had to deploy an environment where the Hosting Kernel can run nodes with capability of running different Guest OS (Virtual Machine, VM) on each node as the Customer choice often varies(choice of Operating System). The following characteristics of Xen were really attractive:-
* Each VM has a dedicated share of memory and disk resources.
* Each VM are isolated from each other providing security
* Choice of using any Distro of Linux (Linux, Debian , Redhat, Suse) and other OS like CentOS, Slackware
* Choice of Control Panels (cPanel, Plesk, Webmin etc)
* Guaranteed Uptime
* Dedicated Backup Server

3.1 Xen Features

Following are the most important features of Xen
* Full root access.
* The amount of memory in the VM plan is exclusively assigned to each VM (can be changed)
* Unmanaged VMs, the customer can manage their VM server, including backups, patching,
applications, backups, firewalling and DNS.
* Swap space equal to twice physical memory (preferred)
* Independent console access, including the ability to reboot your VM
* Backup disk space on a separate backup storage server (Customer can manage and monitor the backups)
* Choice of OS Distros
Fedora Core 7
Fedora Core 6
Fedora Core 4
Debian 4
Debian 3.1
CentOS 5.0
CentOS 4.4
Slackware 11
[ Additional Distros can be added as per the requirements. Xen Guest kernels can be found at
* Choice of Web Hosting Control Panels
cPanel, Plesk , Webmin and most other Control Panels can be used with the VMs. cPanel can be installed only for Fedora and CentOS VMs with a minimum RAM of 256MB. Control Panel installation(cPanel) for the VMs can be done only at startup. Hence clients who needs a Control Panel to manage their domains should get it installed when they setup the VMs because Control Panel installation at a later stage can be complex and hence not preferable.

4. Testing

The Workstation was running Fedora Core 6. The kernel preferred to for dom0/domU is a 2.6.* kernel. As Xen packages were not installed by default , we used Yum to grab the Xen Host Kernel. The VM implementation was done using Xen version 3.04. With a recent version of OS and supported libraries, the host kernel installation was a matter of minutes. RPM installation is also handy provided you have the required libraries.
You can find the RPMs at http://xen.xensource.com/download/
Recent versions can also be found at www.xensource.com
With the Xen Guest kernel (Dom 0 as it is normally called) already installed, the Host kernel needs to be installed now. There are many ways of doing this :-
1. Using the virt-install program (This virtually does everything for you but is not preferred as it is time and resource consuming)
[Refer:- fedoraproject.org ]
2. The next method is easy and preferable (remember we are not newbies to Linux). All you need is to get a Guest Domain(DomU ) Image, create a configuration file for it and create a new “initrd ” . Now you can create your Guest Domain using the Б─° xm createБ─² command and we can find the Guest OS console to work on.
The above links gives you detailed steps for Guest kernel installation. Four Xen Guest nodes with each having 256 MB of RAM using 4 different OS versions(Fedora 6, CentOS5, Debian 4.1, Slackware11) was installed on the Test Workstation and the performance was remarkable.

4.1 Recommended Hardware Specifications

Server Hardware Specification
CPU: 64-bit x86-based system. Intel VT or AMD-V hardware virtualization assist capability : 1.5 GHz single CPU minimum, 2 GHz or faster dual CPU recommended.
Memory: 1 GB of RAM minimum, 2 GB recommended
Disk: 16 GB of disk space minimum, 60 GB of disk space recommended
Network: 100 Mbit/s or faster network interface card
Client Hardware Specification
Minimum specification
300 MHz (Pentium compatible)
128 RAM
200 MB spare disk space

5. Cost Factor

Setting up virtual nodes using Xen depends on the amount of memory used, disk space available, bandwidth usage etc. The amount of RAM allocated to each VM can be changed at any instance of time which is a big advantage. The number of nodes primarily depends on the RAM used and the processor speed. If we are having a good processor and the required amount of RAM , we can run as many VMs as possible. The Guest kernels can be controlled from the Host kernel console. The following table lists out various possible configuration and the cost (approximate).
Plan
Memory
Storage Space
Bandwidth/Month
Monthly Fee
Xen-128
128MB
4GB
40GB
$14
Xen-192
192MB
6GB
75GB
$20
Xen-256
256MB
8GB
100GB
$28
Xen-320
320MB
12GB
125GB
$35
Xen-384
384MB
15GB
150GB
$40
Xen-448
448MB
18GB
175GB
$48
Xen-512
512MB
25GB
200GB
$65
Xen-768
768MB
28GB
300GB
$85
Xen-1024
1024MB
30GB
400GB
$100
Note :- The above table is an approximation. The values can change depending on the type of hardware(Processor and RAM) being used for implementation.
Additional charges can be added depending on the number of the IPs needed and bandwidth usage. Xen installation (Dom0 and DomU ) can be done with in a maximum of 3 hours. This entirely depends on the number of nodes and softwares to be added.

6. Conclusion

Xen provides an excellent way of reducing the total cost of ownership and providing more dependable and high-availability applications in Virtualization platform. It can also deploy a wide variety of services, such as virtual reality servers and local mirroring of dynamic web content. Apart from these , turning the setup and configuration of each OS can be done easily using Xen by which smaller-granularity timescales of hosting is facilitated.
References:

Saturday, August 14, 2010

Xen Virtualization - Installation & Configuration HOWTO


Installing and Configuring Xen
Xen is a server virtualisation solution that works on the principle of Paravirtualisation. 
Paravirtualization requires modifying the operating system to run on Xen. Paravirtualized operating systems "know" that they are virtualized. 
This is achieved by modifying the kernel. Xen is a virtual machine hypervisor.
Xen Hypervisor Requirements

  • A pre-existing Linux or BSD installation as kernel needs to be modified, preferably something running Kernel 2.6 and having Grub as bootloader.
  • x86-compatible system with at least 256MB RAM. More is better.
  • 5GB of spare disk space additional to the disk space you need to install your favorite distribution.
  • Hardware based Xen virtualisation requires Intel VT or AMD-V ( Pacifica ) Processor. To check for Intel VT support look for the 'vmx' flag, or for AMD-V support check for 'svm' flag.
Checking if the processor supports hardware virtualisation.
For Intel
cat /proc/cpuinfo|grep vmx
For AMD
cat /proc/cpuinfo|grep vmx
Installing Xen
There are 3 ways of installing Xen. But installing using yum is the fastest and easiest option. Following are the 3 methods by which Xen can be installed.


1. Using Source code.
2. Using RPM.
3. Using YUM.
Installing using RPM
Download the xen and xen-kernal RPM's according to your OS from and the Xen version you require
http://xen.xensource.com/download/

xen-3.1.0-1.i386.rpm

kernel-xen-2.6.18-3.1.0.i386.rpm

Install each of the the RPM's as shown below.  


# rpm -ivh xen-3.1.0-1.i386.rpm
# rpm -ivh kernel-xen-2.6.18-3.1.0.i386.rpm
After this you need to edit your system's grub config and add a stanza for the Xen hypervisor.


An example of a correctly configured /etc/grub.conf file is given below.
=====================================================================
timeout=5
default=0
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Fedora Core (2.6.18-1.2798.fc6xen)
root (hd0,0)
kernel /boot/xen.gz-2.6.18-1.2798.fc6
module /boot/vmlinuz-2.6.18-1.2798.fc6xen ro root=LABEL=/
module /boot/initrd-2.6.18-1.2798.fc6xen.img
title Fedora Core (2.6.18-1.2798.fc6)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-1.2798.fc6 ro root=LABEL=/
initrd /boot/initrd-2.6.18-1.2798.fc6.img
=====================================================
reboot the machine into the xen kernel. Once the system is booted into the Xen kernel, check to verify the kernel and that Xen is running:
# uname -r
2.6.18-1.2798.fc6xen ( This shows the Xen kernall is running ).
# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 492 1 r—– 1041.7 (Shows the setting of Dom-0)
Building a Guest System on Xen
There are many methods of installing the Guest OS like using virt-install , virt-manager ( GUI option) or using images of OS's. Using the images of OS's is the easiest option. 
We can download the images from sites like http://jailtime.org and use it as a template any number of times. This is also the fastest as we need not install the OS's.
Building a Guest System using `virt-install`
Start the interactive install process by running the virt-install program:
# /usr/sbin/virt-install
The following questions about the new guest OS will be presented. This information can also be passed as command line options; run with an argument of –help for more details. 
Lets us consider the case of installing Fedora Core 6 as the Guest OS.
1.What is the name of your virtual machine? This is the label that will identify the guest OS. This label will be used for various xm commands and also appear in virt-manager the Gnome-panel Xen applet. In addition, it will be the name of the /etc/xen/ configuration file that stores the guest's configuration information.
2. How much RAM should be allocated (in megabytes)? This is the amount of RAM to be allocated for the guest instance in megabytes (eg, 256). Installation requires atleast 256 MB of RAM.
3. What would you like to use as the disk (path)? The local path and file name of the file to serve as the disk image for the guest (eg, /home/nitin/xenfc). This will be exported as a full disk to your guest.
4. How large would you like the disk to be (in gigabytes)? The size of the virtual disk for the guest (only appears if the file specified above does not already exist). 4.0 gigabytes is a reasonable size for a "default" install
5. Would you like to enable graphics support (yes or no): Should the graphical installer be used?
6. What is the install location? This is the path to a Fedora Core 6 installation tree in the format used by anaconda. NFS, FTP, and HTTP locations are all supported. Examples include:
nfs:my.nfs.server.com:/path/to/test2/tree/ *
http://my.http.server.com/path/to/tree/ *
ftp://my.ftp.server.com/path/to/tree
The installation will then commence. If graphics were enabled, a VNC window will open and present the graphical installer. If graphics were not enabled, the standard text installer will appear. Proceed as normal with the installation.
Building a Guest System using Images of OS's
In this process we download the images of root file system of required OS, swap . We then create an an initrd image for the DomU and xm (Xend manager ) to mount it as Root file system. Swap and Initrd of the DomU we are creating. We will consider the case of building a Centos DomU now.
1. Download the DomU image of required OS from http://jailtime.org/ or any other site providing OS images for virtualisation in a to a convenient location on the machine.
2. Untar the downloaded file. The tar file from jailtime.org normally contains the following files.

  1. centos.5-0.img (Image of OS file system )
  2. centos.swap (Swap of OS)
  3. centos.cfg ( Xen configuration file for OS)
3. Create the initrd for DomU using mkinitrd command specifying the kernel version of Dom0.
# mkinitrd /boot/initrd-centos-5.img 2.6.20-1.3001.fc6xen
Some times the initrd images created using above command may not be able to mount the root file system causing Kernel panic. To avoid this create the initrd specifying the following options.
# mkinitrd –with=xennet –preload=xenblk /boot/initrd-centos-5.img 2.6.20-1.3001.fc6xen
When installing kernel-xenU, the initrd is built without xenblk, rendering the system unbootable under Xen using that kernel.
4. In most cases tty will not be enabled which we require for using the console of guest OS (DomU). To enable console we will have to edit the etc/initab file of DomU. For this we mount the image of guest OS ( here centos.5-0.img) as a Loop back device.
# mount -o loop=/dev/loop1 /home/CentOS/centos.5-0.img /home/anydir/
We can now access the files in the image. Open the inittab file and add the following line to it
co:2345:respawn:/sbin/mingetty console
and comment the following lines as shown below.
#1:2345:respawn:/sbin/mingetty tty1
#2:2345:respawn:/sbin/mingetty tty2
#3:2345:respawn:/sbin/mingetty tty3
#4:2345:respawn:/sbin/mingetty tty4
#5:2345:respawn:/sbin/mingetty tty5
#6:2345:respawn:/sbin/mingetty tty6
If that does not work try replacing tty with console to the line specifying getty or mingetty like that is given below.
5:2345:respawn:/sbin/mingetty console
After editing the file unmount the image.
5. Now we need to create the configuration file for DomU. Copy the configuration file provided with the image centos.cfg to preferably /etc/xen directory (Default configuration directory of Xen).
Sample configuration file
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
kernel = "/boot/vmlinuz-2.6.20-1.3001.fc6xen" #Xen Image ( location of kernel of Dom0)
ramdisk = "/boot/initrd-centos-5.img" #DomU's initrd
memory = 256 # DomU memory
name = "centos.5-0″ # Name of DomU
vif = [ '' ]
disk = ['file:/home/CentOS/centos.5-0.img,sda1,w' , 'file:/home/CentOS/centos.swap,sda2,w'] # Location of DomU root filesystem & Swap
ip = "192.168.1.116″ # DomU IP address
gateway = "192.168.1.1″
netmask = "255.255.255.0″
root = "/dev/sda1 ro"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sometimes the network of DomU may not function as xenbr0 ( xen virtual bridge) may not get connected to virtual interface vif. In such case add the following line to xen configuration file.
vif = [ 'bridge=xenbr0', ]
6. Create DomU and mount the file system using following command.
# xm create /etc/xen/centos.cfg -c
( Providing the full path to configuration file or just configuration filename if it inside /etc/xen/ )
The Xend manager (xm) creates the DomU reading the configurations provided in config file. The -c option lets us see all the steps involved in creating and booting into the DomU kernel.
7. We can now check and verify if the DomU is running using the xm list command.
# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 610 1 r—– 12492.1


centos 1 256 1 r—– 256.7


States of domains

  • r – Running
  • b- Blocked
  • c -crashed
  • s -Shutdown
  • p -Paused
We can now enter the console of guest domain using following command.
# xm console
Managing Domains with xm
1. Connecting to a Domain
You can use xm to connect to a domain or virtual machine:
# xm console domain-id
This causes the console to attach to the domain-id's text console.
2. Creating a Domain
You can use xm to make a domain:
# xm create domain001 [-c]
This creates a domain named domain001 with the file residing in the /etc/xen/ directory. The [-c]option aids with troubleshooting by allowing you to connect to the text console.
3. Saving a Domain
You can use xm to save a domain:
# xm save [domain-id] [statefile]
4. Terminating a Domain ID
You can use xm to terminate a domain-id:
# xm destroy [domain-id]
This instantly terminates the domain-id.
5. Shutting Down a Domain
You can use xm to shut down any domain:
# xm shutdown [domain-id]
6. Suspending a Domain
You can use xm to suspend a domain:
# xm suspend [domain-id]
7. Resuming a Domain
You can use xm to resume a previously suspended session:
# xm resume [domain-id]
8. Rebooting a Domain
You can use xm to reboot a domain:
# xm reboot [domain-id]
9. Renaming a Domain
You can use xm to assign a new name to an existing domain:
# xm rename [domain-name] [new domain-name]
Domain renaming will keep the same settings (same hard disk, same memory, etc.).
10. Pausing a Domain
You can use xm to pause a domain:
# xm pause [domain-id]
11. Unpausing a Domain
You can use xm to unpause a domain:
# xm unpause [domain-id]
This makes the domain available for scheduling by a hypervisor.
12. Configuring Memory Allocation
You can use xm to modify a domain's memory allocation:
# xm mem-set [domain-id] [count]
13. Configuring Maximum Memory
You can use xm to modify a domain's maximum memory:
# xm mem-max [domain-id] [count]
You must specify the [count] in megabytes.