|
Written by Kwok Yao Chim
|
|
Friday, 03 October 2008 00:00 |
In this experiment I look at Xen Virtual Server and its ability to virtualize not only Linux OS but also Windows too. And further more you can virtualise a desktop environment through VNC.
Previously I have experimented with virtualization using OpenVZ, this is a very good server virtualization software but it can only virtualise Linux OS such as Redhat, Ubuntu, SuSe, etc.
Having further looked into virtualization, there were different methods to virtualization:
Full Virtualization
Hardware-assisted Virtualization
Paravirtualization
OS Level Virtualization
For now I won't go into these types in detail, but I will say that OpenVZ sits at the OS Level Virtualization.
Xen however puts itself at Hardware-assisted Virtualisation and at Paravirtualization, which in turn allows Windows to run virtually on Linux with Xen.
Before we start this experiment there are a few pre-requisites that need to be fulfilled:
1. Hardware
(the most important ones)
Intel processor with Intel-VT feature
(I have an Core2Duo e6400) to check go to http://developer.intel.com/products/processor_number/chart/core2duo.htm
2GB RAM
Gigabyte Motherboard (I have a 965G-DS3, because the BIOS has a setting for Intel-VT)
100+ GB Hard Drive (just in case you want to setup more than a couple virtual machines).
2. Installation of Base OS
I've chosen CentOS as my base OS because it is based on Redhat EL which means stability, reliability and performance. It is also easier and faster to configure since I'm more familiar with Redhat and Fedora plus the bonus of YUM (I love it).
I used the network installation of CentOS 5.1 to get to the actual CentOS installation screen. If your familiar with the Redhat / Fedora / CentOS installation procedures then all you will need to know are these settings:
Installation Type: Server
Disk Partitioning: Automatic
Create Partitions:
| Device |
Mount Point / Volume
|
Type |
Size (MB)
|
Description |
| LVM Volume Groups |
|
|
|
|
| VG_Guests |
|
|
|
Partition for guest OS which sits on /dev/hda3 |
| VolGroup00 |
|
|
|
Base OS Partition which sits on /dev/hda2/ |
| LogVol00 |
|
Swap |
4096 |
Logical partition for swap (usually 2 x RAM) |
| LogVol01 |
/ |
ext3 |
11264 |
Logical partition for base OS |
| Hard Drives |
|
|
|
|
| /dev/hda |
|
|
|
|
| /dev/hda1 |
/boot |
ext3 |
100 |
boot partition of course (duh!) |
| /dev/hda2 |
VolGroup00 |
LVM PV |
15360 |
Base OS partition |
| /dev/hda3 |
VG_Guests |
LVM PV |
rest of the HDD |
Partition for guest OS |
Network Config: Best to use static IP address and give a hostname of xennode0.yourdomain.com
Firewall Config: No Firewall, and DISABLE SELinux
Choose your language and choose your timezone
Enter your ROOT password
Next choose to install the bare OS, without any additional packages/applications.
(NOTE: if you are installing CentOS 5.1, do not install Xen that comes with this release)
Your installation will begin.
3. Installing Xen
We need to install kernel-xen since this is the kernel that is optimised for running Xen.
NOTE: during the installation of CentOS 5.1 at the package selection stage, there is a Xen package which you can choose, BUT...
this release installs kernel-xen version 2.6.18-53.el5xen which has a bug, It basically hangs on boot, so avoid installing it in the first place. CentOS 5.2 release should be OK.
Type in the following command at the prompt$
$ yum list kernel-xen xen
Loading "installonlyn" plugin
Setting up repositories
utterramblings 100% |=========================| 951 B 00:00
DAGRepo 100% |=========================| 1.1 kB 00:00
updates 100% |=========================| 951 B 00:00
base 100% |=========================| 1.1 kB 00:00
centosplus 100% |=========================| 951 B 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
Installed Packages
kernel-xen.i686 2.6.18-53.1.19.el5 installed
xen.i386 3.0.3-41.el5 installed
Available Packages
kernel-xen.i686 2.6.18-92.1.13.el5 updates
xen.i386 3.0.3-64.el5_2.1 updates
xen.i686 3.0.3-64.el5_2.1 updates
|
As you can see I have kernel-xen 2.6.18-53.1.19.el5 already installed and also the xen hypervisor
The "Updates" repo has a newer version maybe I'll update it... :)
So a simple command to install would be...
|
$ yum install kernel-xen
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
utterramblings 100% |=========================| 951 B 00:00
DAGRepo 100% |=========================| 1.1 kB 00:00
updates 100% |=========================| 951 B 00:00
base 100% |=========================| 1.1 kB 00:00
centosplus 100% |=========================| 951 B 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for kernel-xen to pack into transaction set.
kernel-xen-2.6.18-92.1.13 100% |=========================| 321 kB 00:00
---> Package kernel-xen.i686 0:2.6.18-92.1.13.el5 set to be installed
---> Downloading header for xen to pack into transaction set.
xen-3.0.3-64.el5_2.3.i386 100% |=========================| 89 kB 00:00
---> Package xen.i386 0:3.0.3-64.el5_2.3 set to be updated
--> Running transaction check
--> Processing Dependency: xen-libs = 3.0.3-64.el5_2.3 for package: xen
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for xen-libs to pack into transaction set.
xen-libs-3.0.3-64.el5_2.3 100% |=========================| 33 kB 00:00
---> Package xen-libs.i386 0:3.0.3-64.el5_2.3 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
kernel-xen i686 2.6.18-92.1.13.el5 updates 15 M
Updating:
xen i386 3.0.3-64.el5_2.3 updates 1.8 M
Updating for dependencies:
xen-libs i386 3.0.3-64.el5_2.3 updates 142 k
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 2 Package(s)
Remove 0 Package(s)
Total download size: 17 M
Is this ok [y/N]:
|
It will also check for dependencies, and xen-libs is one of them, you may get a few others.
The installation will have put a few extra files in the /boot directory and it should add an extra entry in the GRUB bootloader menu..
Check out the file /boot/grub/menu.lst
# 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/VolGroup00/LogVol01
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-53.1.19.el5xen)
root (hd0,0)
kernel /xen.gz-2.6.18-53.1.19.el5
module /vmlinuz-2.6.18-53.1.19.el5xen ro root=/dev/VolGroup00/LogVol01
module /initrd-2.6.18-53.1.19.el5xen.img
title CentOS-base (2.6.18-53.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup00/LogVol01
initrd /initrd-2.6.18-53.el5.img 3.0.3-64.el5_2.1 updates
|
The above grub configuration shows in bold where the new Xen kernel stanza should be added, notice the "default=0" line which tells grub to load the first kernel stanza by default.
It is best to install and configure VNCServer at this point as it will help in the process of creating DomU
Now reboot the system to see if it does boot the kernel-xen.
This can be checked by the command "uname -r" at the prompt.
Now if you type in the command...
$ xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 1228 2 r----- 278.9
|
There is a Domain-0 already there and that is the base Xen system also known as Dom0.
All other virtual machines that will be setup are called DomU
4. Creating Virtual Machines
There a few techniques to creating a virtual machine, one for install CentOS (Redhat based) DomU, one for installing a Windows DomU, and a really complicated method for creating a Ubuntu (Debain based) DomU.
In this experiment I will only explain the CentOS DomU method, so get ready...
Looking back at the installation of the Base OS, a partition was created called VG_Guests, that is where all the DomU will be stored.
At the moment the VG_Guests is just physical volume with no logical partitions/volumes.
Have a look at the current logical volumes on the system...
|
$ lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID Sw287L-snkD-hHIP-E9aP-dbSX-fQfn-XXXXX
LV Write Access read/write
LV Status available
# open 1
LV Size 10.06 GB
Current LE 322
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID rFrGf3-AhTX-S4Wm-Mtnj-7z43-imlW-XXXX
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GB
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1
|
There should be two LV, one is the base OS system and the other is the swap.
Now create a new LV for the CentOS DomU...
|
$ lvcreate -L 10G -n vm01_centos52 VG_Guests
Logical volume "vm01_centos52" created
|
The command lvcreate usage is as follows...
lvcreate -L <size_of_LV> -n <name_of_DomU> <name_of_PV>
If a mistake is made use lvremove or lvresize or any lv* command to rectify the appropriate problem.
There is a handy tool that helps you create DomU called virt-install, this command will ask a series of questions before it can create a DomU.
|
$ virt-install
Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems. yes
What is the name of your virtual machine? test_machine
How much RAM should be allocated (in megabytes)? 256
What would you like to use as the disk (path)? /dev/VG_Guests/vm01_centos52
libvir: error : configuration file syntax error: expecting an assignment
libvir: error : configuration file syntax error: expecting an assignment
libvir: error : configuration file syntax error: expecting an assignment
Would you like to enable graphics support? (yes or no) yes
What is the virtual CD image, CD device or install location? http://www.mirrorservice.org/sites/mirror.centos.org/5.2/os/i386/
Starting install...
libvir: error : configuration file syntax error: expecting an assignment
libvir: error : configuration file syntax error: expecting an assignment
libvir: error : configuration file syntax error: expecting an assignment
Retrieving CentOS... 98 kB 00:00
Retrieving boot.iso... 100% |=========================| 7.7 MB 00:07
libvir: error : configuration file syntax error: expecting an assignment
libvir: error : configuration file syntax error: expecting an assignment
libvir: error : configuration file syntax error: expecting an assignment
Creating domain... 0 B 00:00
Unable to connect to graphical console; vncviewer not installed. Please connect to localhost:5902
Domain installation still in progress. You can reconnect
to the console to complete the installation process.
|
The DomU is now started and is ready to install all that is needed is a VNC connection to continue the rest of the installation.
A simple VNCviewer will suffice and connect to the Dom0 IP address along with the given VNC port number in this case...

And the connection will show the familiar CentOS text-based installation screen...

From here you can install your DomU guest as normal.
There is another method to use virt-install and that is to use it with options... for example:
| virt-install -p --location=http://mirrors.eu.kernel.org/centos/5.1/os/i386 --file=/dev/VG_Guests/vm01_centos51 --name=vm01_centos51 --ram=256 |
Check out the "virt-install --help" for more details on options.
You can also use more options to implement a fully automated installation with kickstart, for example:
| virt-install -p --location=http://mirrors.eu.kernel.org/centos/5.1/os/i386 --file=/dev/VG_Guests/vm01_centos51 --name=vm01_centos51 --ram=256 -x "ks=http://localhost/your_kickstart_configfile.cfg" |
|