### Starting from a Fresh CentOS 5.5 Linode
### Enable the native Xen kernel to boot from pvgrub
### It will autoconfigure itself with each yum update.

yum -y install selinux-policy-targeted audit
### Auto-relabel SELinux ext3 xattrs during next boot
touch /.autorelabel

mkdir /boot/grub/

### Write template grub.conf
cat > /boot/grub/grub.conf << EOF
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0)
#          kernel /boot/vmlinuz-version ro root=/dev/xvda
#          initrd /boot/initrd-version.img
#boot=/dev/xvda
default=0
timeout=5
title CentOS (2.6.18-194.26.1.el5xen)
	root (hd0)
	kernel /boot/vmlinuz-2.6.18-194.26.1.el5xen root=/dev/xvda
	initrd /boot/initrd-2.6.18-194.26.1.el5xen.img
EOF

ln -s /boot/grub/grub.conf /boot/grub/menu.lst
ln -s /boot/grub/grub.conf /etc/grub.conf
yum -y install kernel-xen
if [ $? -ne 0 ]; then
    echo "ERROR aborting..."
    exit 1
fi
cat /boot/grub/grub.conf |grep -v 'kernel /boot/xen.gz' | sed -e 's#module /boot/vmlinuz#kernel /boot/vmlinuz#' \
        -e 's#module /boot/initrd#initrd /boot/initrd#' > /boot/grub/grub.conf.new
mv -f /boot/grub/grub.conf.new /boot/grub/grub.conf
KERNELXEN=$(rpm -q kernel-xen)
VERSION=${KERNELXEN##kernel-xen-}xen
mkinitrd -f --preload xenblk /boot/initrd-${VERSION}.img $VERSION

### Make console work
mount /dev/xvda /mnt
mkdir /mnt/dev/pts
umount /mnt
echo "devpts          /dev/pts        devpts  gid=5,mode=620  0 0" >> /etc/fstab
echo "sysfs           /sys            sysfs   defaults        0 0" >> /etc/fstab
sed -i 's#1:2345:respawn:/sbin/mingetty hvc0#co:2345:respawn:/sbin/agetty xvc0 38400 linux#' /etc/inittab
