setting up xen on your debian etch box
xen is a free software virtual machine monitor for IA-32, x86-64, IA-64 and PowerPC architectures. it runs on a host operating system and allows several guest operating systems to be run on top of the host on the same computer hardware at the same time.
you should end up with something like the following, depending on what you chose:
add a bridging interface to
bring up this new interface:
edit
enable this by:
this takes a minute or two. you can follow along with the progress by tailing the log file:
you can list all your images using:
this attaches a console to it and is useful for making sure that it works o.k. when you've got everything working you'll probably want to use a start / stop technique described later.
i.e. your complete bridge definition might look like:
You can use the usual
if you found this article useful, and you are interested in other articles on linux, drupal, scaling, performance and LAMP applications, consider subscribing to my technical blog.
there are many ways to setup xen, but i've put together a simple step-by-step guide to get a working xen system based on debian etch. easy as pie.
install your host system
install a copy of debian etch. you should leave a partition available for lvm, that your virtual machines will use for disk.create a logical volume group
- Get the linux logical volume manager;
apt-get install lvm2 - Initialize your partition (or disk) for lvm;
pvcreate /dev/myLvmPartition - Create a logical volume group on your partition;
vgcreate skx-vg /dev/myLvmPartition
install xen
you can install Xen from the debian packages. Find a list withapt-cache search xen-linux-system. you'll do something like:
# apt-get install xen-tools xen-linux-system-2.6.18-4-xen-686 xen-docs-3.0 libc6-xen# dpkg --list | grep xen
ii libc6-xen 2.3.6.ds1-13etch2
ii linux-image-2.6.18-4-xen-686 2.6.18.dfsg.1-12etch2
ii linux-modules-2.6.18-4-xen-686 2.6.18.dfsg.1-12etch2
ii xen-docs-3.0 3.0.3-0-2
ii xen-hypervisor-3.0.3-1-i386-pae 3.0.3-0-2
ii xen-linux-system-2.6.18-4-xen-686 2.6.18.dfsg.1-12etch2
ii xen-tools 2.8-2
ii xen-utils-3.0.3-1 3.0.3-0-2
ii xen-utils-common 3.0.3-0-2reboot
reboot your system and make sure that you're now running the xen kernel# uname -a
Linux yourhostmachine 2.6.18-4-xen-686 #1 SMP Thu May 10 03:24:35 UTC 2007 i686 GNU/Linuxconfigure a network bridge
get the bridge utils package# apt-get install bridge-utils/etc/network/interfaces
auto xenbr0
iface xenbr0 inet static
pre-up brctl addbr xenbr0
post-down brctl delbr xenbr0
post-up iptables -t nat -F
post-up iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j MASQUERADE
address 192.168.1.1
netmask 255.255.255.0
bridge_fd 0
bridge_hello 0
bridge_stp off# ifup xenbr0/etc/sysctl.conf and uncomment the following line:
net.ipv4.conf.default.forwarding=1# sysctl -p
# echo 1 > /proc/sys/net/ipv4/conf/all/forwardingconfigure your default guest system using xen-tools
you can use xen-tools to configure a default guest system. It's here where you specify what OS you want to use, how networking is configured, how disk is configured etc. This can be overridden when you create a specific guest system, but it's a good idea to configure your starting point.try creating a guest system
you can create a guest system as follows:# xen-create-image --ip=192.168.1.6 --hostname=mymachine# tail -f /var/log/xen-tools/mymachine.log
you can later delete this image using:
# xen-delete-image mymachine# xen-list-imagesboot up that sucker
you can quickly test-boot your new system as follows.# xm create -c mymachine.cfgport forward (optional)
if you want external machines to access ports on your virtual machines you can setup port forwards using IP tables e.g. if you wanted to install apache on one of your virtual machines and have it answer on http://yourhostmachine:80, you'd do the following (which forwards HTTP traffic on your eth0 interface to a virtual machine at address 192.168.1.8). add the following two lines to your network/interfaces file: post-up iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.1.8:80
post-up iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i eth0 -j ACCEPTauto xenbr0
iface xenbr0 inet static
pre-up brctl addbr xenbr0
post-down brctl delbr xenbr0
post-up iptables -t nat -F
post-up iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j MASQUERADE
post-up iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.1.8:80
post-up iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i eth0 -j ACCEPT
address 192.168.1.1
netmask 255.255.255.0
bridge_fd 0
bridge_hello 0
bridge_stp offcloning a machine
one of the great things about Xen, is that it makes it really simple to build a machine exactly the way that you want it, then clone it and distribute it to everyone that needs it. allowing you to:- Easily create development sandboxes
- Create and distribute a standardized development environment
- Create a machine and then build a cluster
- Upgrade machines by duplicating them, patching the duplicates and if everything goes well, switching over to the new machines or rolling back.
create an tarfile of an existing virtual machine
- create a place to store your image
# mkdir /var/xen-images - shutdown the machine that you're planning to clone (duh)
- create a mount point to mount of of your existing images
# mkdir /mnt/xen - mount the image you want to copy
# mount /dev/skx-vg/mymachine-disk /mnt/xen - go to the mount point and tar everything up
# cd /mnt/xen ; tar pcfzv /var/xen-images/myImage.tar.gz * - take a peek at your nice new tar file
# tar tvfz /var/xen-images/myImage.tar.gz - get out of the mount point and unmount.
# cd / ; umount /mnt/xen
i've created a bash script to automate this, posted at the end of this article
creating a virtual machine from a tarfile (like the one created above)
- temporarily comment out any installation method in
/etc/xen-tools/xen-tools.confe.g. this linedebootstrap = 1 - create your image with whatever flags you want e.g.
# xen-create-image --tar=/var/xen-images/myImage.tar.gz --ip=192.168.1.10 --hostname=flossyTheClonedMachine - off you go to happy land.
starting and stopping on boot
If you want to automatically start / stop your machines on bootup, link the machine configuration in/etc/xen/auto e.g.
# mkdir /etc/xen/auto
# ln -s /etc/xen/mymachine.cfg /etc/xen/auto/manually starting and stopping
You can easily start and stop all your xen domains with the handy/etc/init.d/xendomains script e.g. by:
# /etc/init.d/xendomains stopstop, start, restart commands
utilities
take a look at XenMan (apt-get install xenman ), is a nifty little x-windows tool for managing the virtual machines running on your host.
cleaning up the debian install
if you install a debian guest, you should consider some post install steps including:- setup locales:
picking e.g.
# apt-get install locales
# dpkg-reconfigure localesen_US.UTF-8 UTF-8 - set the timezone:
(note: say yes and follow the prompts even if it looks right)
# tzconfig - by default your domU clock is the dom0 clock. this is probably the way you should leave it i.e. install ntp on dom0 and have your domU's use the dom0 synchronized clock. if you want your domU to operate independenly, you'll want to try:
echo 1 > /proc/sys/xen/independent_wallclock
notes
If you are seeing errors like "4Gb seg fixup" spewed to the console, you need toapt-get install libc6-xen
backing up your xen guests
if you need to backup your xen guests, please take a look at my article backing up your xen domains for a discussion on the subject. a flexible script that you can use,xenBackup, is also provided.
setting up a bridging interface
in the configuration above the xen guests are only visible to the xen-host, and any services on the xen-hosts must be accesses via port forwarding, tunneling etc.for some applications, a bridging configuration works better. you can set this up by following the instructions in setting up a xen bridging interface
tech blog
- john's blog
- 3751 reads
Please note, this entry has been closed to new comments.




delicious
digg
reddit
google
yahoo