First, install Debian Stable 32 bit

Edit /etc/apt/sources.list

# echo "
deb http://ftp.debian.org/debian wheezy main contrib non-free
deb http://ftp.debian.org/debian/ wheezy-updates main contrib non-free
deb http://security.debian.org/ wheezy/updates main contrib non-free
deb http://ftp.tuxum.com/tuxum2012R1 wheezy main
" > /etc/apt/sources.list

# apt-get update

- If we are installing a 32 bit OS:
# apt-get install linux-image-686-pae xcp-xapi bash-completion parted firmware-linux-nonfree

- If we are installing a 64 bit OS:
# apt-get install linux-image-amd64 xcp-xapi bash-completion parted firmware-linux-nonfree



# echo "bridge" > /etc/xcp/network.conf

Select xapi toolstack:

# sed -i "s/TOOLSTACK=.*/TOOLSTACK=xapi/" /etc/default/xen

Avoid XenD conflict by disabling:

# sed -i -e 's/xend_start$/#xend_start/' -e 's/xend_stop$/#xend_stop/' /etc/init.d/xen

Add some lines to /etc/default/grub:

# echo "
GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=1024M,max:1024M"
GRUB_DISABLE_OS_PROBER=true
" >>/etc/default/grub

to start dom0 with 1024 MB of RAM and disable OS prober to prevent virtual machines on logical volumes from appearing in the boot menu

Enable bash completion:

# echo "
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
" >>/etc/bash.bashrc

Put xen grub image first:

# dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen

# update-grub2

# init 6

# echo "openvswitch" > /etc/xcp/network.conf

# dpkg-reconfigure xcp-xapi

# /etc/init.d/xcp-xapi restart

Fix qemu network interface script to use openvswitch:

# sed -i "s/brctl addif/#brctl addif/g" /etc/xen/scripts/qemu-ifup
# echo "ovs-vsctl add-port $2 $1" >> /etc/xen/scripts/qemu-ifup

Configure network interface:

# PIF_UUID=$(xe pif-list device=eth0 --minimal)
# IP=$(/sbin/ifconfig eth0 | grep "inet addr:" | awk -F ':' '{print $2}' | awk '{print $1}')
# MASK=$(/sbin/ifconfig eth0 | grep "inet addr:" | awk -F 'Mask:' '{print $2}' | awk '{print $1}')
# GATEWAY=$(netstat -nr | grep "^0.0.0.0" | awk '{print $2}')
# xe pif-reconfigure-ip mode=static DNS=8.8.8.8 \
        ip=$IP netmask=$MASK gateway=$GATEWAY \
        uuid=$PIF_UUID
# cp -n /etc/network/interfaces /etc/network/interfaces.bak-xcp
# cat > /etc/network/interfaces << EOF
auto lo
iface lo inet loopback
EOF

To create a multi-host dmz, using physical interface eth1:

# PIF_UUID=$(xe pif-list device=eth0 --minimal)
# UUID=`xe network-create name-label=dmz0`
# xe vlan-create network-uuid=$UUID pif-uuid=$PIF_UUID vlan=1
# PIF_UUID=$(xe pif-list device=eth0 VLAN=1 --minimal)
# xe pif-reconfigure-ip mode=static ip=192.168.100.1 netmask=255.255.255.0 uuid=$PIF_UUID

This will create a new interface xapiN (xapi0, xapi1, ...) that can be configured on shorewall (you can see who-is-who with ovs-vsctl show, looking for tag parameter equal to vlan on previous command)

Create VM templates:

# /usr/lib/xcp/lib/create_templates

Configure ISO repository

# mkdir /opt/iso

# xe sr-create name-label="ISO library" type=iso content-type=iso device-config:legacy_mode=true device-config:location=/opt/iso

# cd /opt/iso && wget ftp://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/debian-*-amd64-netinst.iso

# init 6

*** Set-up software RAID

- Create partitions with fdisk on both disks (usually /dev/sda and /dev/sdb):

# fdisk /dev/sda
# fdisk /dev/sdb



Options:
	p: list partitions
	n: new partition ('p' for primary). Begin partition on next sector of the last partition
	t: change type of partition (type 'fd' for RAID)
	w: save changes and exit

- (If fdisk says 'no free blocks' use gdisk command instead of fdisk.)

# partprobe /dev/sda
# partprobe /dev/sdb
 

Remove /dev/mapper captured devices:

# for i in `dmsetup table | awk -F ':' '{print $1}'`
do
	dmsetup remove /dev/mapper/$i
done

# mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sda2 /dev/sdb2
# mdadm --create /dev/md3 --level=1 --raid-devices=2 /dev/sda3 /dev/sdb3


- Check new md paritions with:
# cat /proc/mdstat

- Change /etc/fstab swap lines.

For example, add a line like this:

/dev/md2        swap    swap    defaults        0       0

and delete old swap partitions such as:

/dev/sda2	swap	swap	defaults	0	0
/dev/sdb2	swap	swap	defaults	0	0


# mkswap /dev/md2
# swapon -a

- Fix RAID configuration:

# /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf

*** Set-up LVM


# pvcreate /dev/md3
# vgcreate vgxen /dev/md3
# lvcreate vgxen -L 10G -n prueba

# cd /usr/lib/xcp/sm
# ln -s LVHDSR.py LVHDSR
# /etc/init.d/xcp-xapi restart

# xe sr-list
# xe sr-create name-label="ISO library" type=iso content-type=iso device-config:legacy_mode=true device-config:location=/opt/iso
# xe sr-create type=lvhd device-config:device=/dev/vgxen/vms name-label=vms-storage
