If you do a lot of very different projects like we do here at CosmoCode you often need very different environment to test new technologies without interfering with other setups. But using new servers all the time isn't feasible at all.
The solution to this is virtualization. It allows you to run multiple completely independednt systems on the same hardware. We decided to go this way and bought I nice big server to do so. For virtualization we use the open source software XEN.
In the following I will give you some details on how to setup logical volume management (LVM), a XEN “server” (dom-0) and a XEN “client” using Debian's soon-to-be-stable release “Etch”.
Before we continue make sure you have the LVM tools installed:
#> apt-get install lvm2
Getting LVM running is quite simple: partition your harddisk as usual for the host (master) system and create an unformatted partition for management by LVM. For example I created a 1GB swap disk at sda1, a single 10GB root partition at sda2 for the master system and put the rest into sda3.
The next step is to prepare the partition for LVM (think of it like creating a LVM fileystem). This is done with pvcreate.
#> pvcreate /dev/sda3
To use this physical device it needs to be added to a volume group first. Volume groups can span multiple physical devices, but we have only one here. The first parameter to vgcreate is the name of the group. I used the name “vserver” here.
#> vgcreate vserver /dev/sda3
Finally we could create a new virtual device using space from the volume group. This is not needed right now because it will be done later in the xen setup, but for completeness sake I will mention it here. Just use give the size in megabytes, the name of the new device and the volume group name to lvcreate. Then createa filesystem as usual and mount your device:
#> lvcreate -L1500 -ntestdevice vserver
#> mkfs.ext3 /dev/vserver/testdevice
#> mount /dev/vserver/testdevice /mnt
Okay, now we are ready to install the XEN stuff. Fortunately all needed software is in Debian etch already:
#> apt-get install xen-linux-system-2.6.18-3-xen-686 xen-tools
xen-docs-3.0 libc6-xen file xen-hypervisor-3.0.3-1-i386-pae
This will install the xend daemon and kernels for the master and the clients. Before the reboot, a small change in /etc/xen/xend-config.sxp should be done.
(network-script 'network-bridge netdev=eth0')
Now reboot and check uname -a - it should display the XEN enhancement:
Linux hydra 2.6.18-3-xen-686 #1 SMP Mon Dec 4 20:48:20 UTC 2006 i686 GNU/Linux
Now it's time to create a new client system (called domain in XEN lingua). This is easily done with the xen-create-image script, you should configure some defaults in /etc/xen-tools/xen-tools.conf first. Here are my settings:
lvm = vserver
debootstrap = 1
size = 10Gb
memory = 256Mb
swap = 512Mb
fs = ext3
dist = edge
image = sparse
kernel = /boot/vmlinuz-2.6.18-3-xen-vserver-686
initrd = /boot/initrd.img-2.6.18-3-xen-vserver-686
mirror = http://ftp.de.debian.org/debian/
Make sure you configured the LVM volume group and the kernel/initrd images correctly here.
Now install your new vserver by calling
#> xen-create-image –hostname vserver1.mydomain
The script will download the needed packages, install them in newly created logical devices and does create an initial config file in /etc/xen/vserver1.mydomain.cfg
To boot the system use the mighty xm command which is used to control all the domains.
#> xm create /etc/xen/vserver1.mydomain.cfg
You can now connect a virtual console to the just booted system with
#> xm console vserver1.mydomain
Use this to set up a root password and other intitial things, to leave the virtual console use CTRL-]. Note this is not a full terminal, log into your new xen domain with SSH to run fancy stuff like ncurses interfaces.
Okay, that's it. This is the very simplest and basic setup, but should get you going.