Installing and Configuring Xen on a Debian Lenny machine is pretty easy. Firstly, install the system:
apt-get install xen-tools xen-utils-3.2-1 xen-linux-system-2.6.26-2-xen-686
xen-linux-system-2.6.26-2-xen-686 comes with the Xen kernel that you’ll need. It should install a new kernel as the default, and therefore you’ll now need to reboot.
Once rebooted, issue uname -a to ensure that your new Xen kernel is running:
Linux apnic01 2.6.26-2-xen-686 #1 SMP Wed Aug 19 08:47:57 UTC 2009 i686 GNU/Linux
You now have Xen installed! Now, you’ll need to make a few changes. Firstly, none of my new guest VMs had working console, apparently this is a known issue in Lenny with Lenny guests. The work around is to change the inittab on the guest. I wanted to create guests without modifications, so in this case, I edited /etc/xen-tools/xen-tools.conf and uncommented:
#serial_device = hvc0 #default
It’s listed as the default, but uncommenting this seemed to solve my issues.
Now, you’re ready to create your first guest:
xen-create-image –hostname myguest –ip 87.117.X.Y –netmask 255.255.255.192 –gateway 87.117.X.Y –size=40Gb –dist=lenny –memory=128M –dir=/xen/mymachine/ –role=minimal,udev
xen-create-image is part of xen-tools, and puts a front end on the base xen utilities. ‘hostname’ specifies the hostname, and ‘gateway’, ‘ip’ and ‘netmask’ specify the other networking settings. ‘size’ specifies the disk size, which will be a sparse image. ‘dist’ instructs a Debian Lenny guest installation, and ‘memory’ is the amount of RAM that the guest is allowed to use. ‘dir’ specifies where the images will be placed for the VM, and ‘role’ specifies certain what post-installation scripts will be run. ‘minimal’ and ‘udev’ are two available scripts that I found useful to have run on my virtual machines, ‘udev’ installs the udev utilities and fixes various boot up errors, ‘minimal’ installs some minimal base tools.
After a while, your xen machine will be created, and you can now start it with: xm create myguest.cfg
Graceful shutdown with xm shutdown myguest and immediate shutdown with xm destroy myguest
When you wish to gain console access to the machine, use xm console myguest and to release the console and return back to the host, use Ctrl+] (^])
‘top’ won’t be of use in checking load and process details as it will only show the details for the physical host itself, xen comes with xentop which will show you a breakdown of your running guests and their load/CPU time.
xm list will show you details of your running machines, in my case:
xentop - 23:31:06 Xen 3.2-1 10 domains: 2 running, 8 blocked, 0 paused, 0 crashed, 0 dying, 0 shutdown Mem: 4192732k total, 3989084k used, 203648k free CPUs: 2 @ 1808MHz NAME STATE CPU(sec) CPU(%) MEM(k) MEM(%) MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS VBD_OO VBD_RD VBD_WR SSID Domain-0 -----r 40456 0.7 476160 11.4 no limit n/a 2 4 0 0 0 0 0 0 32 ht --b--- 5 0.0 190464 4.5 190464 4.5 1 1 2 301 2 0 1256 93 32 mail --b--- 1891 1.5 524288 12.5 524288 12.5 1 1 388191 204990 2 330 33160 310314 32 ns0 --b--- 1135 0.1 262144 6.3 262144 6.3 1 1 176334 123137 2 93 2446 37966 32 ns1 --b--- 8 0.0 524288 12.5 524288 12.5 1 1 216 533 2 0 3305 350 32 smtp --b--- 377 0.0 262144 6.3 262144 6.3 1 1 34650 43268 2 9 1139 18158 32 staging --b--- 4495 0.1 524288 12.5 524288 12.5 2 1 266044 79026 2 2685 14599 289510 32 sch --b--- 1812 0.1 262144 6.3 262144 6.3 1 1 348604 177876 2 2275 459971 352546 32 www -----r 22 25.9 786432 18.8 786432 18.8 2 1 2189 367 2 0 4661 418 32 pd --b--- 2152 0.0 131072 3.1 131072 3.1 1 1 116707 151119 2 1235 10159 504645 32