Xen

From Logicalwebhost-Wiki

Jump to: navigation, search

Xen is a virtualization technology, which mostly, unless you're CPU is a hacked version, runs a hacked kernel.

You can install it on Debian Etch from the latest source using this how-to: http://howtoforge.net/debian_etch_xen_3.1

this one works better if you want a bunch of machines, or at least more than 4

First remove useless stuff

 apt-get remove exim4 exim4-base lpr nfs-common portmap pidentd pcmcia-cs pppoe pppoeconf ppp pppconfig

Edit your /etc/apt/sources.list and put an # in front of the cdrom line, then make the next lines look like this:

 deb http://debian.osuosl.org/debian/ etch main contrib non-free
 deb-src http://debian.osuosl.org/debian/ etch main contrib non-free

run

 apt-get update
 apt-get upgrade

Configure your network by editing /etc/network/interfaces, make it look something like this:

 # This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5).
 # The loopback network interface  
 auto lo  
 iface lo inet loopback
 # The primary network interface
 allow-hotplug eth0
 iface eth0 inet static
 address 10.1.10.52
 netmask 255.255.255.0
 gateway 10.1.10.1
 auto eth0

install stuff

 apt-cache search xen-linux-system

cut paste the version of that package into the next command

 apt-get install screen ssh debootstrap python python-twisted iproute bridge-utils libcurl3-dev libssl0.9.7
 apt-get install openssh-server vim-full xen-tools xen-linux-system-2.6.18-6-xen-686 xenman xen-docs-3.0 libc6-xen

now make sure your machine boots into the right kernel for xen to work, just look in /boot/grub/menu.1st and look at the default= line, it should match the kernel with xen listed below.

reboot into your new kernel and watch for glitches

 shutdown -r now

you should see the Xen kernel selected when you boot, if not you may have to edit /boot/grub/menu.1st again and fix it.

edit /etc/xen-tools/xen-tools.conf and change the vmlinuz and initrd lines to reflect what you have in /boot, or the next commands won't find the right kernel and initial ramdisk. Also uncomment the password = 1 line so it will prompt you for a root password during the install

now create a new machine with this command, alter to suit your needs (really just set the options in /etc/xen-tools/xen-tools.conf, it will save time with these commands):

 xen-create-image --hostname ns1.bob.com --ide --force --dir=/home/vserver --arch=i386 --kernel=/boot/vmlinuz-2.6.18-xen --debootstrap --dist=etch
 xen-create-image --hostname ns1.bob.com --size=6Gb --swap=256Mb --ip=1.2.3.4 --memory=256Mb --ide --force --dir=/vserver --arch=i386 --kernel=/boot/vmlinuz-2.6.18-xen --debootstrap --dist=etch
 xen-create-image --hostname=mail1.esetresearch.com --size=5Gb --swap=256Mb --ide \
 --ip=10.1.10.55 --netmask=255.255.255.0 --gateway=10.1.10.1 --force \
 --dir=/vserver --memory=32Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.18-5-xen-686 \
 --debootstrap --dist=etch --mirror=http://ftp2.de.debian.org/debian/ --passwd
 xen-create-image --hostname=debfs1.esetresearch.com --ip=10.10.10.10

the start it up by running (change the name to whatever you called your machine):

 xm create /etc/xen/whatevervm.example.com.cfg

If you want to use apt-get to install it, use this one: http://howtoforge.net/debian_etch_xen_from_debian_repository

xm create /etc/xen/xen1.example.com.cfg starts xen1.example.com that you hopefully set up prior
xm console xen1.example.com logs you into your new machine
CTRL ] gets you out of your virtual machine
xm list shows all your virtual machines
xm shutdown xen1.example.com turns off your virtual machine
xm destroy <name> like hitting the power button on a virtual machine
xen-delete-image --dir=/vserver/domains/vm03.example.com vm03.example.com remove a virtual machine created with xen-create-image
ln -s /etc/xen/xen1.example.com.cfg /etc/xen/auto automatically starts your virtual machine on boot

[edit] Move a virtual machine

xm shutdown xen1.example.com turn the machine off
cd /home/vserver/domains/ or wherever you put your virtual machines
cp -R xen1.example.com/* newmachine.example.com could take awhile, copying the whole machine instance
cp /etc/xen/xen1.example.com /etc/xen/newmachine.example.com generate a new config file
vi /etc/xen/newmachine.example.com change a couple configurations, telling the new machine what to do
find this line and change the domain names to newmachine.example.com disk = [ 'file:/home/vserver/domains/bob.coronado.local/disk.img,hda1,w', 'file:/home/vserver/domains/bob.coronado.local/swap.img,hda2,w' ]
find this line and change the domain name name = 'bob.coronado.local'
xm create /etc/xen/newmachine.example.com.cfg starts up your new machine
xm console newmachine.example.com log into your new machine!
vi /etc/hostname change your hostname to whatever you want
CTRL ] get back out of your new machine
xm shutdown newmachine.example.com turns off your virtual machine
xm destroy <name> like hitting the power button on a virtual machine
ln -s /etc/xen/newmachine.example.com.cfg /etc/xen/auto automatically starts your virtual machine on boot

[edit] xen on debian lenny from repo's

this in a Xeon 64 bit server, change all the amd64 instances to i386 if that's what you're using

 apt-get install linux-image-2.6.26-1-xen-amd64 xen-hypervisor-3.2-1-amd64 xen-tools xen-linux-system-2.6.26-1-xen-amd64 \
 linux-headers-2.6.26-1-xen-amd64 bridge-utils

apt-get install linux-image-2.6-xen-vserver-686 xen-hypervisor-3.0.3-1-i386-pae xen-tools xen-linux-system-2.6.18-4-xen-vserver-686 linux-headers-2.6-xen-vserver-686 libc6-xen bridge-utils

Personal tools