[xen-tools-discuss] Centos 5&6

Johan Schurer johannes.schurer at alcatel-lucent.com
Thu Feb 23 10:47:52 CET 2012


Hello all,

I'd like to share my endeavours to get Centos-5 and Centos-6 working with xen-tools so others may benefit from it too.

For centos 5 I created a file 25-setup-kernel script in /usr/lib/xen-tools/centos-5.d
It has the same structure as the other scripts.

#/bin/sh
#
#  This script sets up the kernel and fstab for CentOS 5.
#

prefix=$1

#
#  Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
    . /usr/lib/xen-tools/common.sh
else
    . ./hooks/common.sh
fi

#
# Log our start
#

logMessage Script $0 starting

# Make the console work
sed -i "/Cancelled/ {G;s/$/co:2345:respawn:\/sbin\/mingetty console/;}" ${prefix}/etc/inittab
sed -i "s/^1:2345/#1:2345/" ${prefix}/etc/inittab

# MAKEDEV is needed at this point
chroot ${prefix} ln -s /sbin/MAKEDEV /dev/MAKEDEV
chroot ${prefix} /sbin/MAKEDEV sda sdb sdc sdd

# Create fstab
cat > ${prefix}/etc/fstab << EOF
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
none            /dev/pts        devpts  mode=0620       0       0
EOF

for i in `seq 1 $NUMPARTITIONS`; do
  echo -n "/dev/sda$i " >> ${prefix}/etc/fstab
  eval part=\$PARTITION$i
  if [ ! -z "`echo $part | grep swap`" ]; then
     echo "none swap ws 0 0" >> ${prefix}/etc/fstab
  else
     echo $part | awk -F: '{print $4,$3,$5,0,1}' >> ${prefix}/etc/fstab
  fi
done

# Install the kernel, grub and perl
chroot ${prefix} yum clean expire-cache
chroot ${prefix} yum -y install kernel-xen grub.x86_64 perl.x86_64

KERNELVERSION=`chroot ${prefix} yum list installed version kernel-xen | grep installed | awk '{print $2}'`xen

# Create grub's menu.list
mkdir -p ${prefix}/boot/grub
cat > ${prefix}/boot/grub/menu.lst << EOF
# WARNING : Don't forget to update this when you upgrade kernel !
# You can also exclude kernel-xen from updates by putting
# exclude=kernel-xen in in [main] in yum.conf

default=0
timeout=5
title CentOS ($KERNELVERSION)
kernel        /boot/vmlinuz-$KERNELVERSION
initrd        /boot/initrd-$KERNELVERSION.img
EOF

# Some use lvm but mkinitrd will generate a wrong initrd when these are present.
rm -f ${prefix}/etc/lvm/backup/* ${prefix}/etc/lvm/archive/*

# Generate a correct initrd.
chroot ${prefix} mkinitrd --with=xenblk --with=xennet --preload=xenblk --preload=xennet\
 -f /boot/initrd-$KERNELVERSION.img $KERNELVERSION

#
#  Log our finish
#
logMessage Script $0 finished

========================== cut here =====================

An image can be now generated with:
xen-create-image --force --hostname <your hostname> --ip <your ip> --vcpus 2 --memory=2048M --partition <your partition> --install-method=rinse --dist centos-5 --arch=amd64 --scsi --passwd

It requires rinse 1.9.1 and we use it with LVM.

The big victory was to do the same with centos-6 out of the box.
I copied over the centos-5 directory to centos-6 and added my 25-setup-kernel script but modified it to:

#!/bin/sh
same as above
...

cat > ${prefix}/etc/fstab << EOF
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
none            /dev/pts        devpts  mode=0620       0       0
EOF

for i in `seq 1 $NUMPARTITIONS`; do
  echo -n "/dev/xvde$i " >> ${prefix}/etc/fstab
  eval part=\$PARTITION$i
  if [ ! -z "`echo $part | grep swap`" ]; then
     echo "none swap ws 0 0" >> ${prefix}/etc/fstab
  else
     echo $part | awk -F: '{print $4,$3,$5,0,1}' >> ${prefix}/etc/fstab
  fi
done

chroot ${prefix} yum clean expire-cache
chroot ${prefix} yum -y install kernel-xen grub.x86_64 perl.x86_64 openssh-clients.x86_64

KERNELVERSION=`ls ${prefix}/boot/vmlinuz-* | sed "s#$prefix/boot/vmlinuz-##"`

mkdir -p ${prefix}/boot/grub
cat > ${prefix}/boot/grub/menu.lst << EOF
# WARNING : Don't forget to update this when you upgrade kernel !
# You can also exclude kernel-xen from updates by putting
# exclude=kernel-xen in in [main] in yum.conf

default=0
timeout=5
title CentOS ($KERNELVERSION)
kernel        /boot/vmlinuz-$KERNELVERSION xen_pv_hvm=enable
initrd        /boot/initramfs-$KERNELVERSION.img
EOF

#
#  Log our finish
#
logMessage Script $0 finished

========================== cut here =====================

The thing really was the use of the kernel parameter xen_pv_hvm=enable and the use of /dev/xvde despite the --scsi option of xen-create-image.
So in order to create an image use:

xen-create-image --force --hostname <your hostname> --ip <your ip> --vcpus 2 --memory=2048M --partition <your partition> --install-method=rinse --dist centos-6 --arch=amd64 --passwd

Hope this is of use to someone.

Johan

-- 
Don't you feel more like you do now than you did when you came in?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://xen-tools.org/pipermail/xen-tools-discuss/attachments/20120223/1ed3ed94/attachment.pgp>


More information about the xen-tools-discuss mailing list