Setting up Xen on Debian etch (64bit)
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:
vim /etc/apt/sources.list #comment out the CD line #deb cdrom:[Debian........... apt-get update
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:
vim /etc/network/interfaces
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):
allow-hotplug eth2 iface eth2 inet dhcp
Change yours to match this (of course change eth2 to match yours and whatever IP you wish to use):
auto eth2 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:
/etc/init.d/networking restart
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:
apt-get upgrade 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:
uname -r
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:
vim /etc/xen/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:
vim /etc/xen-tools/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.1 netmask = 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-amd64 initrd = /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:
/etc/init.d/xend restart
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-webial Distribution : etch Fileystem Type : ext3 Size Information ---------------- Image size : 4Gb Swap size : 128Mb Image type : sparse Memory size : 128Mb Kernel path : /boot/vmlinuz-2.6.18-6-xen-amd64 Initrd path : /boot/initrd.img-2.6.18-6-xen-amd64 Networking Information ---------------------- IP Address 1 : 192.168.1.11 Netmask : 255.255.255.0 Gateway : 192.168.1.1 Creating swap image: /home/xen/domains/i-am-webial/swap.img Done Creating disk image: /home/xen/domains/i-am-webial/disk.img Done Creating ext3 filesystem on /home/xen/domains/i-am-webial/disk.img Done 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
Extra Stuff
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:
vim /etc/xen/i-am-webial.cfg
find and edit memory
memory = '512'
Resize the swap to 1GB (Resize Xen DomU swap):
cd /home/xen/domains/i-am-webial dd if=/dev/zero of=swap.img bs=1024k count=1024 mkswap swap.img
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.
debian, Dom0, DomU, server, virtual servers, VPS, xen 

















Stay Updated via RSS





August 9th, 2008 at 6:58 pm
Hello! Really nice how-to. But I have a question (never used Xen before).
Is it possible to create a xen-domain that can work as Gateway? Now I use one server as gateway and one as all the other. Let’s call the gateway gw and the other for server. The gw got Untangle right now and the server got Debian Etch. I’m thinking about removing the gateway and install Untangle as an xen-domain. Is this possible? Or won’t the xen-domain have enought access to the network cards?
- Simon
August 9th, 2008 at 9:14 pm
Simon,
I’m not 100% sure as I’ve never personally used untangle a quick search on their forum suggests it’s possible although I think you need to compile your own kernel:
http://forums.untangle.com/showthread.php?t=2899&highlight=xen
Also a nice big wiki page on Xen networking stuff
http://wiki.xensource.com/xenwiki/XenNetworking
Hope this helps
August 10th, 2008 at 1:23 am
Hey! I’ve been testing some more and found some sweet stuff.
I’ll post the links:
Install everything as they say at howtoforge, but use the amd64 instead.
http://howtoforge.com/debian_etch_xen_from_debian_repository
Use this trick for the network:
http://www.debian-administration.org/articles/470
And use this to configure it:
http://forums.untangle.com/showpost.php?s=5d54606b22858fb02d23434c1c8e349d&p=44&postcount=8
I don’t know yet if it works. I’m a total biginner and this is the first day (or night) that I’v even heard of Xen and the first time I’ve tried it. I hade to reinstall my Workstation just to try this because VMWare doestn’t emulate Intel VT
I’ll tell you how it goes…
August 10th, 2008 at 2:04 am
I changed one thing in the config.
[...]
vnc=0
vncviewer=0
[...]
to
[...]
vnc=1
vncviewer=1
[...]
And I wasn’t able to connect to the server with my vncviewer from the other server so I made an ssh-tunnle and connected via it.
I did this from my laptop:
apt-get install vncviewer
ssh -f -L 5900:localhost:5900 root@192.168.0.29 -N
vncviewer localhost
Niice!
August 10th, 2008 at 9:32 am
Ah cool, so you’ve got it working as a gateway? I might have to give this a try
August 13th, 2008 at 10:35 am
I’ve written some of what I’ve done down.
But I haven’t come to the ioemu, but will update it late.
Check it out:
http://docs.google.com/View?docid=dhsx3w9c_15dgxf3pcf
October 27th, 2008 at 12:34 am
[...] http://27smiles.com/2008/08/08/setting-up-xen-on-debian-etch-64bit/ (para instalar Xen con las versiones estables de Debian) [...]