4- Instalando un domU automáticamente

Imagen de Epe

Este pequeño script te ayudará a instalar Xen automáticamente. Es para discos creados con LVM

Este script bajará los paquetes del sitio de CentOS, si deseas puedes crear un repo local, así hago yo.


#!/bin/bash

[ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ] && [ -n "$4" ] && [ -n "$5" ] && [ -n "$6" ] && [ -n "$7" ]|| { echo "usar: $0 vmname ip netmask gateway password hdsize ram"; exit 1; }

[ -f "/etc/xen/$1" ] &lvcreate dsk -n$1 -L${6}G

cat > /home/centos4.5/ks$1.cfg << EOF
# Kickstart file automatically generated by anaconda.

install
url --url http://mirror.centos.org/centos-4/4/os/i386/.
lang en_US.UTF-8
langsupport --default=en_US.UTF-8 en_US.UTF-8
network --device eth0 --bootproto static --ip $2 --netmask $3 --gateway $4 --nameserver 67.15.31.131 --hostname $1.ecualinux.com
rootpw $5
reboot
firewall --disabled
selinux --disabled
authconfig --enableshadow --enablemd5
timezone America/Guayaquil
bootloader --location=mbr --append="console=xvc0"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --initlabel
part /boot --fstype ext3 --size=100 --asprimary
part swap --size=128
part / --fstype ext3 --size=1 --grow

%packages
@ text-internet
e2fsprogs
-kernel
kernel-xenU
grub
-acl
-anacron
-apmd
-at
-attr
-autofs
-redhat-lsb
-bluez-bluefw
-bluez-hcidump
-bluez-libs
-bluez-utils
-cadaver
-cups
-cups-libs
-dapl
-dhclient
-dhcpv6_client
-dmraid
-dos2unix
-dosfstools
-NetworkManager
-mkbootdisk
-eject
-fbset
-fetchmail
-finger
-fontconfig
-xorg-x11-Mesa-libGL
-xorg-x11-libs
-gpm
-guile
-ibutils
-swig
-ipsec-tools
-irda-utils
-isdn4k-utils
-jpackage-utils
-jwhois
-lftp
-lha
-libjpeg
-libpng
-libtiff
-libusb
-lksctp-tools
-lrzsz
-mt-st
-mtr
-m4
-man
-man-pages
-mutt
-minicom
-mtools
-syslinux
-mdadm
-nc
-nfs-utils
-neon
-parted
-pcmcia-cs
-portmap
-ppp
-procmail
-rp-pppoe
-sendmail
-wvdial
-yp-tools
-ypbind
-quota
-dump
-rsh
-rdate
-rsync
-rdust
-rmt
-stunnel
-slocate
-sudo
-tcl
-talk
-telnet
-tcsh
-setools
-unix2dos
-unzip
-usermode
-kbd
-system-config-mouse
-system-config-network-tui
-system-config-securitylevel-tui
-wireless-tools
-wpa_supplicant
-xinetd

%post
EOF

hwaddr=`python -c 'import random; r=random.randint; print "00:16:3E:%02X:%02X:%02X" % (r(0, 0x7f), r(0, 0xff), r(0, 0xff))'`

#creando la config del xen
cat > /etc/xen/$1 << EOF
kernel = "/boot/kernelinstall45"
ramdisk="/boot/initrdinstall45.img"
memory = $7
name = "$1"
vif = [ 'mac=$hwaddr' ]
disk = [ 'phy:/dev/dsk/$1,xvda,w' ]
extra = "ip=$2 netmask=$3 gateway=$4 dns=67.15.31.131 hostname=$1.ecualinux.com ks=http://67.15.60.47/ks$1.cfg"
on_reboot = 'destroy'
EOF

xm create -c $1

cat > /etc/xen/$1 << EOF
kernel="/boot/vmlinuz-2.6.9-55.ELxenU"
ramdisk="/boot/initrd-2.6.9-55.ELxenU.img"
root = "/dev/xvda3 ro"
memory = $7
name = "$1"
vif = [ 'mac=$hwaddr' ]
disk = [ 'phy:/dev/dsk/$1,xvda,w' ]
on_reboot = 'restart'
on_crash = 'restart'
EOF

xm create -c $1

La instalación queda en menos de 600MB.