Getting Started: Virtualisation with Xen on CentOS using Kickstart

From Clubnix.net

Jump to: navigation, search

This quite quick and dirty howto explains howto setup a CentOS Xen Zone using kickstart.

1) Install Xen and Xen Kernel:

    yum install xen kernel-xen

2) Change boot order to Xen (default=0 in /boot/grub/grub.conf):

    perl -pi -e 's/default=.*/default=0/' /boot/grub/grub.conf

3) Create LVM partition:

    fdisk /dev/sda

    The number of cylinders for this disk is set to 30515.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
       (e.g., DOS FDISK, OS/2 FDISK)

    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 3
    First cylinder (2806-30515, default 2806):
    Using default value 2806
    Last cylinder or +size or +sizeM or +sizeK (2806-30515, default 30515):
    Using default value 30515

    Command (m for help): t
    Partition number (1-4): 3
    Hex code (type L to list codes): 8e
    Changed system type of partition 3 to 8e (Linux LVM)
    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table.

    The new table will be used at the next reboot.
    Syncing disks.

4) Reboot to ensure partition can be added to pvcreate and Xen kernel is booted:

    shutdown -r now

5) Add disk to LVM:

    pvcreate /dev/sda3
      Physical volume "/dev/sda3" successfully created

6) Add lvm cnix group to disk:

    vgcreate cnix /dev/sda3
      Volume group "cnix" successfully created

7) Set up 20 GB vm1 partition:

    lvcreate -n vm1 -L 20G cnix
      Logical volume "vm1" created

8) You need to rescan to create the lvm devices correctly:

    lvscan

9) Download Xen zone kernels into /boot/vm-inst:

    mkdir /boot/vm-inst
    cd /boot/vm-inst

This step for x86 (32 bit systems):

    wget http://mirror.centos.org/centos/5/os/x86/images/xen/initrd.img
    wget http://mirror.centos.org/centos/5/os/x86/images/xen/vmlinuz

This step for x86_64 (64 bit systems):

    wget http://mirror.centos.org/centos/5/os/x86_64/images/xen/initrd.img
    wget http://mirror.centos.org/centos/5/os/x86_64/images/xen/vmlinuz

10) Install and start Apache2

    yum install httpd
    /etc/init.d/httpd start

11) Create the kickstart file:

32 bit URL for x86 (32 bit systems):

    cat << _EOF_ > /var/www/html/vm1-inst-ks.cfg
    install
    shutdown
    url --url http://mirror.centos.org/centos/5/os/x86
    lang en_US.UTF-8
    network --device eth0 --bootproto static --ip 192.168.0.123 --netmask 255.255.255.0 --gateway 192.168.0.1 --nameserver 192.168.0.10 --hostname vm1
    rootpw change_1ns74ll
    firewall --enabled --port=22
    authconfig --enableshadow --enablemd5
    selinux --disabled
    timezone --utc Europe/Amsterdam
    bootloader --location=mbr --driveorder=xvda --append="console=xvc0"
    clearpart --all --initlabel --linux --drives=xvda
    part /boot --fstype ext3 --size=100 --ondisk=xvda
    part pv.2 --size=0 --grow --ondisk=xvda
    volgroup VolGroup00 --pesize=32768 pv.2
    logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
    logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=272 --grow --maxsize=544

    %packages
    @base
    @core
    screen
    mtr
    -bluez-utils
    -bluez-libs
    -bluez-gnome
    -smartmontools
    -mdadm
    -acpid
    -cpuspeed

    %post
    /sbin/chkconfig --level 123456 cups off
    /sbin/chkconfig --level 123456 netfs off
    /sbin/chkconfig --level 123456 nfslock off
    /sbin/chkconfig --level 123456 pcscd off
    /sbin/chkconfig --level 123456 portmap off
    /sbin/chkconfig --level 123456 sendmail off
    /sbin/chkconfig --level 123456 gpm off
    /sbin/chkconfig --level 123456 rpcgssd off
    /sbin/chkconfig --level 123456 rpcidmapd off
    _EOF_

64 bit URL for x86_64 (64 bit systems):

    cat << _EOF_ > /var/www/html/vm1-inst-ks.cfg
    install
    shutdown
    url --url http://mirror.centos.org/centos/5/os/x86_64
    lang en_US.UTF-8
    network --device eth0 --bootproto static --ip 192.168.0.123 --netmask 255.255.255.0 --gateway 192.168.0.1 --nameserver 192.168.0.10 --hostname vm1
    rootpw change_1ns74ll
    firewall --enabled --port=22
    authconfig --enableshadow --enablemd5
    selinux --disabled
    timezone --utc Europe/Amsterdam
    bootloader --location=mbr --driveorder=xvda --append="console=xvc0"
    clearpart --all --initlabel --linux --drives=xvda
    part /boot --fstype ext3 --size=100 --ondisk=xvda
    part pv.2 --size=0 --grow --ondisk=xvda
    volgroup VolGroup00 --pesize=32768 pv.2
    logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
    logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=272 --grow --maxsize=544

    %packages
    @base
    @core
    screen
    mtr
    -bluez-utils
    -bluez-libs
    -bluez-gnome
    -smartmontools
    -mdadm
    -acpid
    -cpuspeed

    %post
    /sbin/chkconfig --level 123456 cups off
    /sbin/chkconfig --level 123456 netfs off
    /sbin/chkconfig --level 123456 nfslock off
    /sbin/chkconfig --level 123456 pcscd off
    /sbin/chkconfig --level 123456 portmap off
    /sbin/chkconfig --level 123456 sendmail off
    /sbin/chkconfig --level 123456 gpm off
    /sbin/chkconfig --level 123456 rpcgssd off
    /sbin/chkconfig --level 123456 rpcidmapd off
    _EOF_

12) Create vm1-inst start file:

    cat << _EOF_ > /etc/xen/vm1-inst
    kernel = "/boot/vm-inst/vmlinuz"
    ramdisk = "/boot/vm-inst/initrd.img"
    name = "vm1-inst"
    memory = 160
    disk = [ 'phy:/dev/cnix/vm1,xvda,w', ]
    vif = ['bridge=xenbr0', ]
    vcpus = 1
    ip = '192.168.0.123'
    netmask = '255.255.255.0'
    gateway = '192.168.0.1'
    extra = "text ks=http://_DOMAIN0_IP_/wm-inst1-ks.cfg ip=192.168.0.123 netmask=255.255.255.0 gateway=192.168.0.1 dns=192.168.0.10"
    _EOF_

13) Manually replace IP (192.168.0.123), netmask(255.255.255.0), gateway (192.168.0.1), nameserver (192.168.0.10), hostname (wm1) and UTC timezone (Europe/Amsterdam) on point 11 and 12.

14) Adapt _DOMAIN0_IP_ to IP of the Domain 0:

    DOMAIN0_IP=`awk -F= '/IPADDR=/ {print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0` perl -pi -e 's/_DOMAIN0_IP_/$ENV{DOMAIN0_IP}/'
    /etc/xen/vm1-inst

15) Match physical CPU's with virtual per zone:

    cpu=`grep processor /proc/cpuinfo | wc -l` perl -pi -e 's/vcpus.*/vcpus = $ENV{cpu}/' /etc/xen/vm1-inst

16) Start vm-inst zone

    xm create -c vm1-inst

17) When you see that it want's to reboot, then shut it DOWN instead:

    xm shutdown vm1-inst

18) Create normal vm1 start file:

    cat << _EOF_ > /etc/xen/vm1
    name = "vm1"
    memory = "160"
    disk = [ 'phy:/dev/cnix/vm1,xvda,w', ]
    vif = [ 'bridge=xenbr0', ]
    bootloader="/usr/bin/pygrub"
    vcpus=1
    on_reboot   = 'restart'
    on_crash    = 'restart'
    _EOF_

19) Match physical CPU's with virtual per zone:

    cpu=`grep processor /proc/cpuinfo | wc -l` perl -pi -e 's/vcpus=.*/vcpus=$ENV{cpu}/' /etc/xen/vm1

20) Start vm1 zone

    xm create -c vm1

21) Login in change password, update and reboot zone.

(Note that root password is: change_1ns74ll)

    passwd root
    yum update
    shutdown -r now
Personal tools