There are many howtos out there. This one is mine.
The howtos that I consulted in setting this up were the following:
The first thing I did was to upgrade the freshly provided Squeeze installation to Wheezy. This I did simply by editing /etc/apt/sources.list and replacing squeeze with wheezy, and commenting out the lines for backports. Then:
apt-get update apt-get dist-upgrade
Now install the packages needed to run Xen:
apt-get install xen-linux-system xen-tools
Now prioritise the Xen kernels over the normal ones:
dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen update-grub
For this specific setup, we ordered an extra /28 network for the Xen hosts. The first of these ip addresses were assigned to dom0 (the host itself) by changing /etc/network/interfaces. For this example, I use 172.16.150.224/28, but you should of course replace that with the real thing:
auto eth0 iface eth0 inet static address 172.16.1.125 broadcast 172.16.1.127 netmask 255.255.255.224 gateway 172.16.1.97 up ip addr add 172.16.150.225/28 dev eth0
At this point you can reboot the machine, and it should come up in the xen kernel, which you can verify by running:
xm list
Next we need to edit a few network settings, by editing /etc/sysctl.conf:
net.ipv4.ip_forward=1 net.ipv4.conf.all.rp_filter=1 net.ipv4.conf.default.proxy_arp=1 net.ipv4.icmp_echo_ignore_broadcasts=1 net.ipv6.conf.all.forwarding = 1
Then reload network settings:
sysctl -p
Now edit /etc/xen/xend-config.sxp and configure as follows (comment out other settings):
(network-script network-route) (vif-script vif-route) (dom0-min-mem 1024) (enable-dom0-ballooning no) (total_available_memory 0) (dom0-cpus 0) (vncpasswd '')
Then restart xen:
/etc/init.d/xen restart
Next you need to configure LVM. On this particular host, the bulk of the space was assigned to /home, which was unused as no user accounts had been created yet. Setting up LVM was therefore an easy task. First you edit /etc/fstab and remove /home from it. Assuming that /dev/md3 was mounted on /home, you then:
umount /home pvcreate /dev/md3 vgcreate vg0 /dev/md3
Now configure xen-tools by editing /etc/xen-tools/xen-tools.conf. For this setup, we default to ubuntu 12.04:
lvm = vg0 install-method = debootstrap size = 120Gb # Disk image size. memory = 768Mb # Memory size swap = 1536Mb # Swap size fs = ext3 # use the EXT3 filesystem for the disk image. dist = precise image = sparse # Specify sparse vs. full disk images. gateway = 172.16.150.225 netmask = 255.255.255.240 broadcast = 172.16.150.239 passwd = 1 kernel = /boot/vmlinuz-`uname -r` initrd = /boot/initrd.img-`uname -r` arch = amd64 mirror = http://archive.ubuntu.com/ubuntu/
Configure your firewall. I prefer using firehol for this sort of thing. First install firehol:
apt-get install firehol
Then edit /etc/firehol/firehol.conf:
version 5 FIREHOL_LOG_MODE="ULOG" interface eth0 internet protection strong 500/sec server "icmp ssh http https" accept client all accept # Allow traffic from eth0 to reach the XEN hosts router xenr inface eth0 outface vif+ server "icmp ssh http https" accept client all accept
Test your firewall:
firehol try
Then edit /etc/default/firehol and set:
START_FIREHOL=YES
Finally, build your first virtual host:
xen-create-image --hostname=guest1.example.com --ip=172.16.150.226
This will take quite a while, depending on the speed of your mirror. Start it:
xm create /etc/xen/guest1.example.com.cfg
You can view console with:
xm console guest1.example.com
And you can exit from the console using ctrl+]. You should also be able to ssh to the host.