Xen

From Cheatsheet

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

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

 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

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.domain.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.domain.com --ip=10.10.10.10

Contents

Lenny install

 apt-get install xen-linux-system-2.6.26-2-xen-686 xen-tools
 apt-get install xen-linux-system-2.6.26-1-xen-amd64 xen-tools
 vi /boot/grub/menu.1st
   set kernel to xen one you just installed, it's probably already done
 http://wiki.debian.org/Xen
 reboot
 mkdir /home/xen
 vi /etc/inittab
   comment out #1:2345:respawn:/sbin/getty 38400 tty1
   add 1:2345:respawn:/sbin/getty 38400 hvc0
   comment out #2:23:respawn:/sbin/getty 38400 tty2
   add 2:23:respawn:/sbin/getty 38400 tty1
 vi /etc/xen-tools/xen-tools.conf
   uncomment dir = /home/xen
   change dist = lenny
   uncomment gateway = xx.xx.xx.xx
   uncomment netmask = xx.xx.xx.xx
   uncomment passwd = 1
   uncomment serial_device = hvc0
 vi /etc/xen/xend-config.sxp
   uncomment (network-script network-bridge)
   comment out (network-script network-dummy)
 /etc/init.d/xend restart
 xen-create-image --hostname=mail.logicalwebhost.com --size=10Gb --ip=192.168.1.110 --role=udev
 mkdir /etc/xen/auto
 ln -s /etc/xen/your.hostname.com.cfg /etc/xen/auto/your.hostname.com.cfg
 xm console mail.logicalwebhost.com
 apt-get install udev
 vi /etc/fstab
   add this line to the end
   none            /dev/pts      devpts    defaults        0   0
 mount -a

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

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

root password reset

 mkdir /vserver/vm_base
 mount -o loop /vserver/domains/somedomain/disk.img /vserver/vm_base
 chroot /vserver/vm_base
 passwd root
 exit
 umount /vserver/vm_base
 xm create /etc/xen/somedomain.cfg
 xm console somedomain

resize xen guest image

 cd /whereveryourxendiris/domains/machinename/
 cp disk.img disk.bk
 md5sum disk.bk
 md5sum disk.img (make sure they match)
 dd if=/dev/zero of=Tempfile bs=1024 count=5000000 (5G new temp file)
 cat Tempfile >> disk.img
 rm Tempfile
 resize2fs -f disk.img
 fsck.ext3 disk.img
 xm create /etc/xen/whateverthemachinenameis.cfg
Personal tools