2006-02-07, 07:08 PM
Ok so XEN just rules.. I use it at work to test new OS builds and such. I can have a complete development enviroment under my current desktop. So here is a quick little howto on getting XEN up and running on centos 4.0 as the host OS and ttylinux as a guest OS. ttylinux is a very stripped down version of linux.. around 16 megs.. so its good to get it running
This will go into explaining how to install the binary version of XEN. If anyone is interested in the source howto I can do that too. If you do the source build.. you can custom build your kernel to meet your needs. Xen is a very active project so the latest xen kernel is 2.6.12.6
So first, i use a basic centos install with all the development libraries. Its no different really then a basic server install but with the development libraries installed. The xen install script will tell you if something is missing later on. I needed to use apt-get to install 1 package first
Code:
apt-get install bridge-utils
So lets download and extract the xen binary version
Code:
wget http://www.cl.cam.ac.uk/Research/SRG/netos/xen/downloads/xen-3.0.1-install-x86_32.tgz
tar zxfv xen-3.0.1-install-x86_32.tgz
cd xen-3.0.1-install
Now lets run the install script. This basically just copies over the binaries in install/ dir into /
Code:
sh ./install.sh
You should see something like this at the end
Code:
Checking to see whether prerequisite tools are installed...
Xen CHECK-INSTALL Tue Feb 7 13:52:19 EST 2006
Checking check_brctl: OK
Checking check_hotplug: OK
Checking check_iproute: OK
Checking check_python: OK
Checking check_zlib_lib: OK
All done.
If one of those errors out you'll need to install that package to make it work. Just keep re-running the install.sh script
Now for centos and I'm sure other distro's You have to create a ram image to preload the console info into ram before loading the kernel. If this isn't here I got errors about not being able to load the console
Code:
mkinitrd /boot/initrd-2.6.12.6-xen0.img 2.6.12.6-xen0
Now you want to edit your grub.conf.. in centos/fedora there is a symlink at /etc/grub.conf that points to the location of the grub config in /boot. So you want to add this line before the others
Code:
title XEN (2.6.12-zen)
root (hd0,0)
kernel /xen.gz dom0_mem=65536 noreboot
module /vmlinuz-2.6.12.6-xen0 root=/dev/hda3 ro
module /initrd-2.6.12.6-xen0.img
Below is my grub.conf file
Code:
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title XEN (2.6.12-zen)
root (hd0,0)
kernel /xen.gz dom0_mem=65536 noreboot
module /vmlinuz-2.6.12.6-xen0 root=/dev/hda3 ro
module /initrd-2.6.12.6-xen0.img
title CentOS (2.6.9-22.0.1.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-22.0.1.EL ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.9-22.0.1.EL.img
title CentOS 4.0 (2.6.9-5.0.3.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-5.0.3.EL ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.9-5.0.3.EL.img
You can put the XEN one at the bottom.. you just want to change the default= line to default boot your XEN kernel. 0 is the first listing and 1 would be the 2nd and so on.
Now for fedora there is this thing called tls.. I am not gonna go into why we don't want that in XEN but just disable it. If this directory is present on your system
Code:
mv /lib/tls /lib/tls.disabled
now reboot and you should be booted up with your new XEN kernel. you can verifiy by running the uname -a command like below
Code:
[root@unused xen-3.0.1-install]# uname -a
Linux unused.ip.244.domain.com 2.6.12.6-xen0 #1 Tue Jan 31 16:03:21 GMT 2006 i686 i686 i386 GNU/Linux
Ok great now xen is running. So lets start the xen service and make sure it will run on bootup
Code:
service xend start
chkconfig xend on
Now we want to make our first guest system. Like i said above I will be using ttylinux which already provides a xen image.. so lets so that to test it out.
So lets grab the image. I like to put the images in /opt/xen dir. So this part will think you are using that dir.. feel free to change it since some of these images you can make them as big as you want to meet the space needs of your guest system
Code:
mkdir /opt/xen
cd /opt/xen/
wget http://easynews.dl.sourceforge.net/sourceforge/xen/ttylinux-xen.bz2
bzip2 -d ttylinux-xen.bz2
Now we need to make the config file to load it all up
So this create a new file in /etc/xen/ttylinux and put the contents in like this
Code:
kernel = "/boot/vmlinuz-2.6-xenU"
memory = 64
name = "ttylinux"
vif = [ '' ]
ip = "192.168.1.3"
disk = ['file:/opt/xen/ttylinux-xen,sda1,w']
root = "/dev/sda1 ro"
don't change the kernel = line
you can change the memory line to meet your needs.. just don't go over the memory allocated on your host
the name= line can be changed if you want to use mulitple guests of the same image
don't touch the vif= line
you'll eant to change the ip = line to meet your needs
the disk = line will change if you put the image in anywhere other then /opt/xen
Now leave sda1 alone.. my host machine is not using scsi drives.. its just emulation some scsi devices on the guest OS so this is OK. and leave root = the same
So now lets start it up and see if it works
Code:
xm create -c /etc/xen/ttyLinux
You should see a boot cycle and it will go pretty quickly. You should be brought to a command prompt now where you can login with the root/root password
Now you can login.. now for me I have to fill out nameserver info and also add the default route. For me it was like this.. feel free to use this dns server if you don't know yours off hand
Code:
echo "nameserver 66.193.31.10" > /etc/resolv.conf
route add default gw 192.168.1.1
Later I will explain how to add that into the ttylinux image.
Now with your nameserver info and default route added you can now ping hosts
Code:
root@tiny ~ # ping google.com
PING google.com (64.233.187.99): 56 data bytes
64 bytes from 64.233.187.99: icmp_seq=0 ttl=242 time=42.1 ms
64 bytes from 64.233.187.99: icmp_seq=1 ttl=242 time=31.0 ms
Now you can detatch by using the following key combo ctrl+]
now you could view the following to connect to the tiny HTTP server running on your guest
[/url][url=http://192.168.1.3]http://192.168.1.3
That should show you
Code:
Congratulations!
You have successfully installed ttylinux.
See the ttylinux homepage for updates.
For information on how to use the retawq web browser, visit its documentation page.
Now if you want to connect back into the running guest OS you would run the following command
Code:
xm console ttylinux
Hit enter a few times and the prompt should show right back up.. You can get a running list of your domains by running
Code:
xm list
You can destroy a dom by
Code:
xm destroy ttylinux
I will get into how to do more advanced builds later.. this is just a stater.. hope you like it.. be sure to join us on #linux-noob on efnet and tell Jy how much he rules