UNIX / How to configure and use XEN : Redhat specifics

Home | UNIX | Practical

How to configure and use XEN : Redhat specifics
Pierre-Philipp Braun <pbraun@nethence.com>

XEN Guide : pbraun.nethence.com/doc/sysutils_xen/xen.html
XEN Redhat specific : pbraun.nethence.com/doc/sysutils_xen/xen_redhat.html


Redhat dom0 & domU
Postinstall relevant practices,
rpm -qa > /root/rpm.dist.txt
fdisk -l > /root/fdiskl.dist.txt
cp /etc/fstab /root/fsdisk.dist.txt
vi /etc/syslog.conf && service syslog restart
Eventually install net-snmp, snmp-utils, lm_sensors, screen, gpm and also iftop (ex-parrot.com/~pdw/iftop/)

Configure the default init to 3,
vi /etc/inittab
for example,
id:3:initdefault:


Redhat dom0
During installation, check the Virtualization and Gnome (to get some nice gtk theme on virt-manager) sets.

Otherwise make sure those packages are installed,
rpm -qa | less
then search (/) for,
libvirt
virt-manager
python-virtinst
libvirt-python
xen
xen-libs
gnome-applet-vm

Eventually configure a repo pointing to the release tree,
vi /etc/yum.repos.d/centos.repo
for example,
name=CentOS 5.1 local copy
baseurl=file:///data/centos51
enabled=1
gpgkey=file:///data/centos51/RPM-GPG-KEY-CentOS-5
gpgcheck=1

Redhat domU
To make remote repos from dom0, either use HTTP,
rpm -qa | grep httpd
rmdir /var/www/html
ln -s /mnt/cdrom /var/www/html
service httpd start
FTP,
or NFS,
vi /etc/exports
for example,
/data/centos51  *(ro,no_root_squash)
Note on SLES one more nfs option is required by default (eeeeek)


DomU autostart
Make links from guest's configs in here,
/etc/xen/auto


Make a template
Export /mnt/cdrom as NFS,
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
vi /etc/exports
  /mnt/cdrom  *(ro,no_root_squash)
Then run this,
virt-install -n default -r 256 -f /data/default/default.disk -s 10 --nographics -p -l nfs:192.168.0.2:/mnt/cdrom
Note. -s 10 means 10Go
Note. don't say 127.0.0.1 here otherwise the XEN Guest will boot but won't be able to install the packages.

Once the packages installation is finished, it congrats ans needs to reboot. Back to the command line, keep access to the console while it's rebooting,
xm co default
first boot launches "setup". Deactivate security level and SELinux. Once it's booted, also tweak this,
chkconfig microcode_ctl off

At last,
- Shutdown the VM (shutdown -h now from the domU or "xm sh default" from dom0.
- Remove uuid and mac address from guest's config.
- To ways to get a SPARSE capable template,
tar cvzSf
cp
Note. "cp --sparse=always" works too.


bootstraping Redhat domU
Note this is not recommended as it may alter the dom0 (pbraun.nethence.com/code/scdomurhel.sh). I wouldn't even use rinse for that (www.xen-tools.org/software/rinse/). But anyways here's the tip. Place the tar archive into VM's folder, for example /data, create the virtual disk, mount it. In example,
cd /data
mkdir vmname
cd vmanme
dd if=/dev/zero of=vmname.ext3 bs=1024k count=10000 seek=1
Note "seek=" is usefull for sparse disks. Copiable with cp --sparse=always (default) and tarable with tar -S/--sparse.
mkfs.ext3 -F vmname.ext3
mkdir loop
mount -o loop vmname.ext3 loop
Create the swap virtual disk,
dd if=/dev/zero of=vmname.swap bs=1024k count=1000
Note no "seek=" here.
mkswap -L swap vmname.swap

Configure e.g. /etc/yum.repos.d/centos.repo and use yum like that,
vi /etc/yum.repos.d/centos.repo
for example,
[centos]
name=CentOS 5.1 local copy
baseurl=file:///data/centos51
enabled=1
gpgkey=file:///data/centos51/RPM-GPG-KEY-CentOS-5
gpgcheck=1
Thereafter try,
yum clean all
yum --installroot=/data/lala install MAKEDEV (mgetty dep)

Create the devices,
cd loop/dev
./MAKEDEV console
./MAKEDEV init
./MAKEDEV net
./MAKEDEV null
Note null is needed for PAM rpm's %post
Note if using dom0's MAKEDEV,
MAKEDEV -d /path/to/dev init

Then,
yum --installroot=/data/lala --exclude=Deployment_Guide-en-US groupinstall Core
Note --exclude=notification-daemon --exclude=kernel --exclude=microcode_ctl (optional)

Otherwise here another list of important packages,
MAKEDEV
fdisk
device-mapper
module-init-tools
e2fsprogs
  bash
vim-minimal
setup
rpm
gcc
glibc-devel
gcc++ (libstdc dep)
net-tools-1.60-73
yum
system-config-network-tui
elfutils (elfutils-libs dep)
net-tools
passwd
shadow-utils

Install additionnal packages,
yum -y --installroot=$pwd/$vmname/loop install man \
  system-config-securitylevel-tui \
  system-config-network-tui \
  setuptool \
  which \
  mlocate \
  screen \
  mailx \
  xorg-x11-xauth \
  xorg-x11-apps \
  portmap \
  nfs-utils-lib-1.0.8-7.2.z2 \
  nfs-utils-1.0.9-24.el5

Edit fstab,
/dev/xvda1 / ext3 defaults 1 1
/dev/xvda2 swap swap  defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
Disable TLS,
echo 'hwcap 0 nosegneg' > loop/etc/ld.so.conf.d/libc6-xen.conf
or (old way),
mv loop/lib/tls loop/lib/tls.disabled
Create some dirs,
mkdir -p loop/var/log
Remove root's password to login,
vipw
or
sed -e 's/root:\*:0:0:root/root::0:0:root/' loop/etc/passwd
Fix modprobe,
cat > loop/etc/modprobe.conf << EOF
alias eth0 xennet
alias scsi_hostadapter xenblk
EOF
Prepare a bare network config,
cat > loop/etc/sysconfig/network << EOF
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=vmname
EOF
and network interface,
cat > loop/etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
DEVICE=eth0
ONBOOT=yes
TYPE=Ethernet
EOF

prepare domU's kernel inside dom0,
cp `ls -1t /boot/vmlinuz-*xen | head -1` .
cp `ls -1t /boot/initrd-*xen.img | head -1` .
Edit the initrd,
mkdir tmp-initrd
cd tmp-initrd
gzip -dc ../initrd.dist | cpio -id
mv init init.tmp
sed -n -e '1,/mkblkdevs/p' init.tmp > init
cat >> init << EOF
echo "Loading xenblk.ko module"
insmod /lib/xenblk.ko
echo "Loading jbd.ko module"
insmod /lib/jbd.ko
echo "Loading ext3.ko module"
insmod /lib/ext3.ko
EOF
sed -n -e '/mkblkdevs/,$p' init.tmp | sed -e '1d' \
  | sed -n -e '/mkblkdevs/,$p' \
  | sed -e 's#mkrootdev .*#mkrootdev -t ext3 -o defaults,ro /dev/xvda1#' \
  >> init
chmod 700 init
rm -rf lib/*.ko
tmp=`/lib/modules/`ls -1t /lib/modules/ | grep xen$ | head -1`
cp -R $tmp/kernel/drivers/xen/blkfront/xenblk.ko lib \
  && cp $tmp/kernel/fs/jbd/jbd.ko lib \
  && cp $tmp/kernel/fs/ext3/ext3.ko lib \
  && echo done
  unset tmp
chmod 600 lib/*.ko
rm -f init.tmp
(find . | cpio -c -o | gzip -9) > ../initrd
  rm -f initrd.dist
  rm -rf tmp-initrd

Do other confs like screenrc and syslog, at last.

Note in case you really need to chroot,
mount -o bind /proc loop/proc
mount -o bind /sys loop/sys

Return to vm's main dir and unmount the virtual disk, in example,
cd /data/vmname
umount loop

Create vm's configuration,
cat > $vmname << EOF
name = "$vmname"
memory = "256"
disk = ['tap:aio:$pwd/$vmname/$vmname.ext3,xvda1,w',\\
  'tap:aio:$pwd/$vmname/$vmname.swap,xvda2,w']
vif = [ 'bridge=xenbr0' ]
kernel = "$pwd/$vmname/vmlinuz"
ramdisk = "$pwd/$vmname/initrd"
#extra = "init=/bin/sh"
root = "/dev/xvda1"
vcpus=1
on_reboot = 'restart'
on_crash = 'restart'

Start the VM in single user mode (vm config:extra=/bin/sh),
depmod -a
chkconfig acpid off
chkconfig apmd off
chkconfig autofs off
chkconfig bluetooth off
chkconfig cups off
chkconfig firstboot off
chkconfig gpm off
chkconfig haldaemon off
chkconfig hidd off
chkconfig smartd off


References
fedoraproject.org/wiki/Docs/Fedora8VirtQuickStart
people.redhat.com/dshaks/
www.karan.org/blog/index.php/2005/12/06/xen3_on_centos4 ==> www.karan.org/mock/Xen/
centos.karan.org/


Sat Nov 8 12:19:50 CET 2008
       © 2008 Pierre-Philipp Braun