Last active
January 12, 2017 14:22
-
-
Save aleks-mariusz/0a8e4040b21974e6668c01b0c2328b7b to your computer and use it in GitHub Desktop.
xenserver7 automated (unattended) installation using cobbler, a trigger script to work with cobbler.sync, also the post-install depends on this answerfile (treated as a kickstart file by cobbler) - sets up small OS partition, and whatever left over space as the xen-storage-repository, installs gluster, and if two disks of same size seen, mirrors…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $1 -ne 0 ]]; then | |
echo "ERROR: failed install, backing out changes" | |
mdadm --stop /dev/md{0,1,2,3} | |
mdadm --zero-superblock /dev/sd{a,b}{1,4,5,6} | |
sgdisk --zap /dev/sdb | |
exit | |
fi | |
FIRSTBOOT_INIT1=/etc/init.d/create_storage_repository | |
FIRSTBOOT_INIT2=/etc/init.d/install_gluster | |
MAX_DISKS=2 | |
DISKS=$(fdisk -l 2>/dev/null | awk '$1 ~ /^Disk/ && $2 ~ /\/dev\// {print substr($2,0,length($2)-1)}') | |
NUM_DISKS=$(echo $DISKS|wc -w) | |
echo "INFO: found $NUM_DISKS disks" | |
if [[ $NUM_DISKS -gt $MAX_DISKS ]]; then echo "ERROR: more than $MAX_DISKS disks not supported" >&2; exit 1; fi | |
echo "INFO: creating new partiton" | |
sgdisk --new=4::-34 /dev/sda | |
DATA_DEV=/dev/sda4 | |
if [[ $NUM_DISKS -eq 2 ]]; then | |
DISK_SRC=/dev/sda | |
DISK_DST=/dev/sdb | |
echo "INFO: checking both disks are the same size" | |
DISK_SRC_SZ=$(fdisk -l $DISK_SRC 2>/dev/null|awk '$1 ~ /^Disk/ && /bytes/ {printf "%s%s\n", $3, substr($4,0,length($4)-1)}') | |
DISK_DST_SZ=$(fdisk -l $DISK_DST 2>/dev/null|awk '$1 ~ /^Disk/ && /bytes/ {printf "%s%s\n", $3, substr($4,0,length($4)-1)}') | |
if [[ "$DISK_SRC_SZ" != "$DISK_DST_SZ" ]]; then echo "ERROR: $DISK_SRC is $DISK_SRC_SZ but $DISK_DST is $DISK_DST_SZ" >&2; exit 1; fi | |
echo "INFO: encapsulating root partition" | |
sgdisk --typecode=1:fd00 /dev/sda | |
mdadm --create /dev/md0 --level=1 --raid-devices=2 --run --metadata=0.90 /dev/sda1 missing | |
echo "INFO: encapsulating /var/log partition" | |
sgdisk --typecode=5:fd00 /dev/sda | |
mdadm --create /dev/md1 --level=1 --raid-devices=2 --run --metadata=0.90 /dev/sda5 missing | |
echo "INFO: copying partition table to second disk" | |
sgdisk -R /dev/sdb /dev/sda | |
echo "INFO: mirroring root to second disk" | |
mdadm -a /dev/md0 /dev/sdb1 | |
sleep 5 | |
grep -q recovery /proc/mdstat | |
while [ $? -eq 0 ]; do | |
sleep 5 | |
grep -q recovery /proc/mdstat | |
done | |
resize2fs -f /dev/md0 | |
e2fsck -f /dev/md0 | |
echo "INFO: mirroring /var/log to second disk" | |
mdadm -a /dev/md1 /dev/sdb5 | |
# not waiting for this one, let it run in the background | |
# swap partition | |
mdadm --create /dev/md2 --level=0 --raid-devices=2 --run --metadata=0.90 /dev/sda6 /dev/sdb6 | |
# data partition | |
mdadm --create /dev/md3 --level=0 --raid-devices=2 --run --metadata=0.90 /dev/sda4 /dev/sdb4 | |
DATA_DEV=/dev/md3 | |
mount /dev/md0 /tmp/root | |
mount -o bind /dev /tmp/root/dev | |
mount -t sysfs none /tmp/root/sys | |
mount -t proc none /tmp/root/proc | |
mount -t tmpfs none /tmp/root/tmp | |
mount -o bind /run /tmp/root/run | |
cat > /tmp/root/etc/mdadm.conf <<-_EOF | |
MAILADDR root | |
auto +imsm +1.x -all | |
DEVICE /dev/sd*[a-z][1-9] | |
_EOF | |
mdadm --detail --scan >> /tmp/root/etc/mdadm.conf | |
SWAP_LABEL=$(awk '$2 ~ /^swap$/ {print substr($1,7)}' /tmp/root/etc/fstab) | |
sed -i 's/quiet/rd.auto rd.auto=1/' /tmp/root/boot/grub/grub.cfg | |
chroot /tmp/root grub-install /dev/sdb | |
chroot /tmp/root dracut --mdadm --fstab --add='dm mdraid' --filesystems ext3 --add-drivers='raid1 raid0' --force /boot/initrd-`uname -r`.img `uname -r` -M | |
# wait until /var/log resync done before wrapping up | |
sleep 5 | |
grep -q recovery /proc/mdstat | |
while [ $? -eq 0 ]; do | |
sleep 5 | |
grep -q recovery /proc/mdstat | |
done | |
resize2fs -f /dev/md1 | |
e2fsck -f /dev/md1 | |
mkswap -L $SWAP_LABEL /dev/md2 | |
else | |
mount /dev/sda1 /tmp/root | |
mount /dev/sda5 /tmp/root/var/log | |
mount -o bind /dev /tmp/root/dev | |
mount -t sysfs none /tmp/root/sys | |
mount -t proc none /tmp/root/proc | |
mount -t tmpfs none /tmp/root/tmp | |
mount -o bind /run /tmp/root/run | |
fi | |
# first boot init script that will create a sr based on the new storage volume | |
cat > /tmp/root/$FIRSTBOOT_INIT1 <<_EOF | |
#!/bin/bash | |
# chkconfig: 3 99 99 | |
# description: xs_create_sr | |
echo "INFO: creating storage repository" | |
/opt/xensource/bin/xe sr-create content-type=user type=ext device-config:device=$DATA_DEV shared=false name-label="Local storage" | |
rm -f $FIRSTBOOT_INIT1 | |
_EOF | |
chmod +x /tmp/root/$FIRSTBOOT_INIT1 | |
chroot /tmp/root /usr/sbin/chkconfig --add $FIRSTBOOT_INIT1 | |
# first boot init script that will install gluster server | |
cat > /tmp/root/$FIRSTBOOT_INIT2 <<_EOF | |
#!/bin/bash | |
# chkconfig: 3 99 99 | |
# description: gluster_inst | |
echo "INFO: installing gluster" | |
sleep 15 # let networking kick in ? | |
sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Base.repo | |
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm | |
wget -P /etc/yum.repos.d https://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/CentOS/glusterfs-epel.repo | |
yum --releasever=7 -y install glusterfs glusterfs-fuse glusterfs-server | |
systemctl start glusterd.service | |
rm -f $FIRSTBOOT_INIT2 | |
_EOF | |
chmod +x /tmp/root/$FIRSTBOOT_INIT2 | |
chroot /tmp/root /usr/sbin/chkconfig --add $FIRSTBOOT_INIT2 | |
umount /tmp/root/{run,tmp,proc,sys,dev,} | |
sync;sync | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<installation mode="fresh" srtype="lvm"> | |
<keymap>us</keymap> | |
<primary-disk gueststorage="no">sda</primary-disk> | |
<source type="url">http://$server/cblr/links/$distro</source> | |
<root-password>password</root-password> | |
<script stage="installation-complete" type="url">http://$server/cblr/aux/xenserver/post-install</script> | |
<admin-interface name="eth0" proto="static"> | |
#set $nic = $interfaces["eth0"] | |
#set $ip = $nic["ip_address"] | |
#set $netmask = $nic["netmask"] | |
<ip>$ip</ip> | |
<subnet-mask>$netmask</subnet-mask> | |
<gateway>$gateway</gateway> | |
</admin-interface> | |
<name-server>192.168.1.254</name-server> | |
<timezone>Europe/London</timezone> | |
<hostname>$hostname</hostname> | |
<time-config-method>ntp</time-config-method> | |
<ntp-server>17.254.34.125</ntp-server> | |
</installation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# this file goes into: /var/lib/cobbler/triggers/sync/post to clean up after cobbler sync runs. | |
# | |
# largely based on http://ikenticustech.blogspot.co.uk/2011/04/xenserver-citrix-cobbler-part-one.html | |
# but updated for xenserver7 | |
libdir=/var/lib/cobbler | |
srcdir=/var/www/cobbler | |
dstdir=/var/lib/tftpboot | |
for profile in $( grep -l xenserver7.ks $libdir/config/profiles.d/* ); do | |
json=${profile##*/} | |
name=${json%.json} | |
[[ -d $dstdir/images/$name ]] && rsync -avq $srcdir/ks_mirror/$name/{install.img,boot/vmlinuz} $dstdir/images/$name/ | |
done | |
# xenserver7 needs 1024M memory, any less and you will get errors during the yum phase | |
for file in $( grep -l xen.gz $dstdir/pxelinux.cfg/* ); do | |
sed -i'' -e 's!initrd=\(/images/.*/\)\(xen.gz \)ks.*ks=\(.*\)$!\1\2dom0_mem=1024M com1=115200,8n1 console=com1,vga --- \1vmlinuz xencons=hvc console=hvc0 console=tty0 answerfile=\3 install --- \1install.img!;' $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you use cobbler, you wont be able to use the /var/lib/tftpboot/pxelinux.0 that comes with cobbler with xenserver, as the mboot.c32 file that xenserver wants to use is incompatible and the pxe process will hang.. you will need to use the pxelinux.0 in /var/www/cobbler/ks_mirror/XenServer-7.0.0/boot/pxelinux (when you cobbler import) the distro..