Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XEN howto
#1

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

Reply
#2

So if you want to edit the image to add in the default gateway and nameserver info you do this

 



Code:
mkdir /mnt/image
mount -o loop /opt/xen/ttylinux-xen /mnt/image/
cd /mnt/image/etc/




 

Now edit resolv.conf and add the following.. You can change the IPs to meet your needs or use these

 



Code:
nameserver 38.8.82.2
nameserver 38.8.81.2




 

Now edit the file network.conf

 

There is this line #GATEWAY="1.2.3.4" remove the # in front and change the ip with your gateways IP info

Then look for NETWORKING="no" change the no to a yes

 

now lets umount it and if you destroy your dom and create it again.. the nameserver and default gateway should be all setup

 



Code:
cd ~/
umount /mnt/image




Reply
#3

nice post Jy !

 

will this work in Fedora by any chance ?

 

cheers

anyweb

Reply
#4
yep it will work good in fedora.. but I believe core4 has xen kernel rpms
Reply
#5

great how to, i tried to install from source myself because i have a 64bit arch. i havnt tried it out yet though. before i continue though, can you use Windows XP as a guest OS, and if so, could you do a how-to on that for those of us who only want windows for those few essential programs that can only work (smoothly) on windows?

 

thanks.

Reply
#6

no you can't use windows as a guest OS.. from what I know about windows and the gpl you can put gpl code into the windows kernel.. right now there are only some linux images

 

here is the 64bit version

 

[/url]http://www.cl.cam.ac.uk/Research/SRG/netos...tall-x86_64.tgz

 

Here is a quick little howto on how to get a slackware image running. Jailtime.org has a few user contributed images you can run

 

So lets grab the slackware image

 

You can grab it at [url=http://jailtime.org/download:slackware:v10.2]http://jailtime.org/download:slackware:v10.2

That also tells you everything about what is installed and special instructions about the image. The first thing you notice is the image is only around 100megs. That is compressed.. now when you extract it the image file will actually be 1gig. This is due to having all the empty space being 0's so the compression can easily handle that and really shrink it down good

 

So now lets put the image in /opt/xen like up before

 



Code:
tar zcfv slackware.10-2.20050917.img.tgz




 

That has these files in them

 



Code:
slackware.10-2.img  slackware.10-2.xen.cfg  slackware.swap




 

The image file is the 1gig image file.

the .swap file is what is used for the guest OS's swap partition

and the .cfg file should go into /etc/xen

 



Code:
mv slackware.10-2.xen.cfg /etc/xen




 

now lets edit the /etc/xen/slackware.10-2.xen.cfg to meet our needs. Mine looks like this

 



Code:
kernel = "/boot/vmlinuz-2.6-xenU"
memory = 128
name = "slackware.10-2"
nics = 1
ip = "192.168.1.5"
gateway = "192.168.1.1"
netmask = "255.255.255.0"
disk = ['file:/opt/xen/slackware.10-2.img,sda1,w','file:/opt/xen/slackware.swap,sda2,w']
root = "/dev/sda1 ro"




 

Now as you notice I pass in the ip/netmask and gateway into the guest. You can remove them and just do ip = dchp and it will grab a IP from your dhcp server if you have one running

 

Now lets run it

 



Code:
xm create -c /etc/xen/slackware.10-2.xen.cfg




 

Now you should be brought to a prompt.. yay slackware guest OS up and running

Reply
#7

That's very nice tutorial. I am going to setup my testbed by using xen as well. But I still have some questions about this

 

1. How can I find image of Fedora or any other linux distributions ?

2. incase I have to create 10 guests, do i need to have 10 image files? is it possible to use just 1 image for 10 guests? if yes, how about the configuration in each guest system?

3. How to assign IP address to other interfaces of guest?

Let's say, in the configuration file i use "nic=3" , but in the "IP" filed it's for eth0. How about eth1 and eth2.

4. Is it possible to connect each guest together? For example, i create 3 guests and use guest1 as a router to connect guest2 and guest3 together and create routing policy and so on.

 

That's all it make me confuse right now... ^___^

 

Thx

Reply
#8

Very nice post. I followed it and tried to create domain 1 to run ttylinux, but failed. See the attached file for the output.

 

I am running it on Inspiron 4100 laptop, total memory=128M. Domain1 wasn't able to successfully start up.

 

My question is: is my ttylinux correct?

Why ttylinux wasn't able to start up?

 

Thank you!

xen_ttylinux.txt



Attached Files
.txt   xen_ttylinux.txt (Size: 9.81 KB / Downloads: 1,028)
Reply
#9

Hi!

 

Thanks for the nice article. However, I had a problem on the portion of xm create area.

 

I downloaded a Fedora image at [/url][url=http://www.jailtime.org/]http://www.jailtime.org/ and mount it using your article. However, at the final stage I encountered this error, as follows:

 

[root@vmsrv xen-images]# xm create fedora.fc6.xen3.cfg

Using config file "./fedora.fc6.xen3.cfg".

Error: Device 2049 (vbd) could not be connected.

File /home/xen-images/fedora.fc6.img is loopback-mounted through /dev/loop0,

which is mounted in the privileged domain,

and so cannot be mounted by a guest.

 

 

I placed the image:

/home/xen-images/fedora.fc6.img

 

And my config:

 

kernel = "/boot/vmlinuz-2.6.20-2925.13.fc7xen"

memory = 512

name = "fedora.fc6"

vif = [ '' ]

dhcp = "dhcp"

disk = ['file:/home/xen-images/fedora.fc6.img,sda1,w', 'file:/home/xen-images/fedora.swap,sda2,w']

root = "/dev/sda1 ro"

 

 

How can I resolve the problem? Please help me. I'm stuck for almost 2 weeks already. Can't seem to find definite solutions everywhere.

 

Thank you so much.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)