Setting up Xen on Debian etch (64bit)08 August 2008
Today I decided to setup Xen (not the Half-Life world) on a clean Debian installation so I could have a few VPSes to play around with load balancing mySQL, FastCGI and Mongrel. I thought I’d break down the steps I went though to get the basic Xen setup working.
Note: This is by no means a perfect setup, it’s more of a quick way to play around with Xen using a spare PC in the home. If you want more of a production level setup I suggest checking out the Xen website, or Google.
Step 1. Install Debian (Etch)
Here you just need to setup a standard Debian system, I’m using the 64bit edition of Etch but the process is the same for most Debian releases. I won’t go into detail on how to setup Debian as there are plenty of how-tos out there, for me the normal setup was fine. During the installation I gave the machine judgement as the hostname and gnet.foo as the domain (you can use whatever) I also unchecked desktop from the selectable software menu as I didn’t need/or want a GUI.
Step 2. Configure Debian ready for Xen
Once you’ve booted and logged into your system you need to install a few applications, but before we do that I tend to remove the CD source from apt-get’s sources.list:
#comment out the CD line
Now install the packages (remove vim-full if you're not using vim):
apt-get install ssh build-essential vim-full
Next we need to configure the server to use a static IP (if you didn't during the installation). I gave my box (judgement) a static IP of 192.168.1.10. Open up the interfaces file:
Now if you selected DHCP during the installation your file should look similar to this by default (eth2 was my interface, yours might be different):
iface eth2 inet dhcp
Change yours to match this (of course change eth2 to match yours and whatever IP you wish to use):
auto eth iface eth2 inet static address 192.168.1.10 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1
Once you've done that you need to restart the networking:
If all is working then you should be able to ping other computers on your network and they should be able to ping your machine.
If you wish you can continue the rest of the setup via SSH (on windows you can use Putty).
Finally just make sure your system is up-to-date before giving it a reboot:
shutdown -r now
Step 3. Installing Xen
There are two main options when it comes to installing Xen. You can compile it from the source code or simply use apt-get, the latter worked fine for me and is dead simple...to install via apt-get use the following command (bridge-utils is used to setup the network for the virtual machines):
apt-get install xen-linux-system-2.6.18-6-xen-amd64 bridge-utils
The version of Xen kernel might of changed since writing this, try this command to see what's there:
apt-cache search xen-linux When that has finished installing give the machine a reboot and select Xen kernel from the GRUB menu (for me it became the default option):
shudown -r now
Once the system is back up and logged in (your previous credentials should work) check that you've booted the correct kernel:
It should read something like 2.6.18-6-xen-amd64 if not then you've most likely booted the wrong kernel from GRUB.
Step 4. Creating virtual images or DomU's (the VPSes)
To help with creating, starting, stopping, etc... you need to install xen-tools:
apt-get install xen-tools
Next we need to create the place we want to store the domains (virtual servers), I put mine in /home/xen (xen requires a folder called domains within this folder) so run this command:
mkdir -p /home/xen/domains
Once you've created the location to store the domains you need to edit a few options in Xen's configuration. Start by opening up xend-config.sxp:
and look this for line (around line 70 for me):
### To bridge network traffic, like this:## dom0: fake eth0 -> vif0.0 -+# |# bridge -> real eth0 -> the network# |# domU: fake eth0 -> vifN.0 -+## use## (network-script network-bridge)
and uncomment the network-script network-bridge part so it looks like this:
### To bridge network traffic, like this:## dom0: fake eth0 -> vif0.0 -+# |# bridge -> real eth0 -> the network# |# domU: fake eth0 -> vifN.0 -+## use#(network-script network-bridge)
Now we need to setup some defaults as well as the location to store the domains by opening up xen-tools.conf:
There are several things to comment out and change here so I'll just list the values I changed in mine:
...dir = /home/xen...debootstrap = 1...dist = etch#If you want to give your domains static IP's rather than use DHCP (which I did then you can setup the default gateway/netmask)gateway = 192.168.1.1netmask = 255.255.255.0...#This bit is important, as mine differed to the default you need to change kernel and initrd to point to the right ones (ls /boot/* - to find out)kernel = /boot/vmlinuz-2.6.18-6-xen-amd64initrd = /boot/initrd.img-2.6.18-6-xen-amd64...#Change this to your prefered mirror (for me that's the UK):mirror = http://ftp.uk.debian.org/debian/
Restart Xen to make sure the configuration loads correctly:
You should now be ready to create your first domain. If you're happy with the defaults in the xen-tools.conf file then you can leave a lot of the options out or you can of course put them as arguments of the command, check the man pages for xen-create-image for more information:
xen-create-image --hostname=i-am-webial --ip=192.168.1.11 --netmask=255.255.255.0 --gateway=192.168.1.1 --passwd
You should see output of something like this:
General Infomation--------------------Hostname : i-am-webialDistribution : etchFileystem Type : ext3
Size Information----------------Image size : 4GbSwap size : 128MbImage type : sparseMemory size : 128MbKernel path : /boot/vmlinuz-2.6.18-6-xen-amd64Initrd path : /boot/initrd.img-2.6.18-6-xen-amd64
Networking Information----------------------IP Address 1 : 192.168.1.11Netmask : 255.255.255.0Gateway : 192.168.1.1
Creating swap image: /home/xen/domains/i-am-webial/swap.imgDone
Creating disk image: /home/xen/domains/i-am-webial/disk.imgDone
Creating ext3 filesystem on /home/xen/domains/i-am-webial/disk.imgDone
Installing your system with debootstrap mirror http://ftp.uk.debian.org/debian/............
Once it's finished you can start your domain by using the following command:
xm create /etc/xen/i-am-webial.cfg
Open a console for the domain:
xm console i-am-webial
you can exit the console by doing Ctrl + ].
To shutdown a domain:
xm shutdown i-am-webial
Increase the RAM of the domain:
find and edit memory
memory = '512' 512
Resize the swap to 1GB (Resize Xen DomU swap):
dd if=/dev/zero of=swap.img bs=1024k count=1024
Expand the file system by 4 GB (Resize Xen DomU disk)
dd if=/dev/zero bs=1GB count=4 >> disk.img
resize2fs -f disk.img
Hopefully you should now all be setup with basic VPSes, if you need any help with problems please feel free to contact me. You may also leave any feedback/comments you wish below.