Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ganapathichidambaram/628c52d33acec4b43617d9e45bc7628f to your computer and use it in GitHub Desktop.
Save ganapathichidambaram/628c52d33acec4b43617d9e45bc7628f to your computer and use it in GitHub Desktop.
Few Sample of pre installation script using kickstart configuration for Custom partition by checking list of disk
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# START pre-kvmhost-partitions
#
set \$(list-harddrives)
echo "\$@"
disk=( \$1 \$3 )
size=( \$2 \$4 )
echo "S1: \${size[0]} S2: \${size[1]}"
echo "D1: \${disk[0]} D2: \${disk[1]}"
# Make PV assignments based on size
if [[ \${size[0]} < \${size[1]} ]] ; then
root_d=\${disk[0]}
data_d=\${disk[1]}
else
root_d=\${disk[1]}
data_d=\${disk[0]}
fi
echo "ROOT: \$root_d"
echo "DATA: \$data_d"
cat << EOF > /tmp/partinfo
part /boot --fstype ext3 --size 200 --ondisk=\$root_d --asprimary
part swap --recommended --ondisk=\$root_d --asprimary
part pv.root --size=1024 --grow --ondisk=\$root_d
part pv.data --size=1024 --grow --ondisk=\$data_d
volgroup vg00 pv.root
volgroup vg01 pv.data
logvol / --fstype ext3 --size=1024 --vgname=vg00 --name=root --grow
logvol /srv --fstype ext3 --size=1024 --vgname=vg01 --name=data --grow
EOF
#
# END pre-kvmhost-partitions
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%pre
#!/bin/sh
hds=""
mymedia=""
for file in /proc/ide/h* do
mymedia=`cat $file/media`
if [ $mymedia == "disk" ] ; then
hds="$hds `basename $file`"
fi
done
set $hds
numhd=`echo $#`
drive1=`echo $hds | cut -d' ' -f1`
drive2=`echo $hds | cut -d' ' -f2`
#Write out partition scheme based on whether there are 1 or 2 hard drives
if [ $numhd == "2" ] ; then
#2 drives
echo "#partitioning scheme generated in %pre for 2 drives" > /tmp/part-include
echo "clearpart --all" >> /tmp/part-include
echo "part /boot --fstype ext3 --size 75 --ondisk hda" >> /tmp/part-include
echo "part / --fstype ext3 --size 1 --grow --ondisk hda" >> /tmp/part-include
echo "part swap --recommended --ondisk $drive1" >> /tmp/part-include
echo "part /home --fstype ext3 --size 1 --grow --ondisk hdb" >> /tmp/part-include
else
#1 drive
echo "#partitioning scheme generated in %pre for 1 drive" > /tmp/part-include
echo "clearpart --all" >> /tmp/part-include
echo "part /boot --fstype ext3 --size 75" >> /tmp/part-include
echo "part swap --recommended" >> /tmp/part-include
echo "part / --fstype ext3 --size 2048" >> /tmp/part-include
echo "part /home --fstype ext3 --size 2048 --grow" >> /tmp/part-include
fi
#-----------------------------------------------cut-----------------------------------------
# main part of kickstart
# include the partitioning logic from the pre section.
%include /tmp/part-include
%pre
# pre section
#----- partitioning logic below--------------
# pick the first drive that is not removable and is over MINSIZE
DIR="/sys/block"
# minimum size of hard drive needed specified in GIGABYTES
MINSIZE=60
ROOTDRIVE=""
# /sys/block/*/size is in 512 byte chunks
for DEV in sda sdb sdc sdd hda hdb; do
if [ -d $DIR/$DEV ]; then
REMOVABLE=`cat $DIR/$DEV/removable`
if (( $REMOVABLE == 0 )); then
echo $DEV
SIZE=`cat $DIR/$DEV/size`
GB=$(($SIZE/2**21))
if [ $GB -gt $MINSIZE ]; then
echo "$(($SIZE/2**21))"
if [ -z $ROOTDRIVE ]; then
ROOTDRIVE=$DEV
fi
fi
fi
fi
done
echo "ROOTDRIVE=$ROOTDRIVE"
# drives smaller than 240GB use fixed-size partions
# drives larger than 240GB use percentage-based partition sizes
if [ $GB -lt 240 ]; then
# drives smaller than 240GB
cat << EOF > /tmp/part-include
zerombr
clearpart --all --drives=$ROOTDRIVE --initlabel
#clearpart --all --drives=$ROOTDRIVE
bootloader --location=mbr --driveorder=$ROOTDRIVE
part /boot --fstype ext3 --size=300 --ondisk=$ROOTDRIVE
part pv.8 --size=100 --grow --ondisk=$ROOTDRIVE
volgroup VolGroup00 --pesize=65536 pv.8
logvol / --fstype ext3 --name=root --vgname=VolGroup00 --size=30000
logvol swap --fstype swap --name=swap --vgname=VolGroup00 --size=8000
logvol /tmp --fstype ext3 --name=tmp --vgname=VolGroup00 --size=10000
logvol /var/log --fstype ext3 --name=varlog --vgname=VolGroup00 --size=1000
logvol /usr/vice/cache --fstype ext3 --name=usrvicecache --vgname=VolGroup00 --size=17000
EOF
else
# drives 240GB and larger
cat << EOF > /tmp/part-include
zerombr
clearpart --all --drives=$ROOTDRIVE --initlabel
#clearpart --all --drives=$ROOTDRIVE
bootloader --location=mbr --driveorder=$ROOTDRIVE
part /boot --fstype ext3 --size=300 --ondisk=$ROOTDRIVE
part pv.8 --size=100 --grow --ondisk=$ROOTDRIVE
volgroup VolGroup00 --pesize=65536 pv.8
logvol / --fstype ext3 --name=root --vgname=VolGroup00 --percent=12
logvol swap --fstype swap --name=swap --vgname=VolGroup00 --percent=4
logvol /tmp --fstype ext3 --name=tmp --vgname=VolGroup00 --percent=4
logvol /var/log --fstype ext3 --name=varlog --vgname=VolGroup00 --percent=1
logvol /usr/vice/cache --fstype ext3 --name=usrvicecache --vgname=VolGroup00 --percent=7
EOF
fi
#-----------------------------------------------cut-----------------------------------------
#
# Kickstart config file. Produces the actual kickstart file to be given
# to anaconda. Documentation for each option is listed in the comments
# above where the option is produced.
#
# This file documents as many of the kickstart keywords and options as
# possible. The models do not support all the options, but more are
# added as needed.
#
# Some document names are abbreviated:
#
# SAG: RHEL4 System Administration Guide, English edition
# (rhel-sag-en.pdf)
#
#platform=x86, AMD64, or Intel EM64T
# Required
#
# Kickstart Specific Settings
#
# lang
# SAG p9
# lang is the language used during install.
# langsupport is the set of languages to be supported on the installed system.
# keyboard is the keyboard connected to the system.
lang en_US
# Perform kickstart in text mode. There's no need for a graphical build,
# even off a CD/DVD.
# text: SAG pg16
text
# Install or upgrade?
# install: SAG p8
# upgrade: SAG p16
install
# Use NFS installation media
nfs --server=buildserver.mydomain.com --dir=/export/centos/5.5/os/x86_64
# Network settings
network --device eth0 --bootproto static --ip 192.168.1.3 --netmask 255.255.255.0 --gateway 192.168.1.254 --nameserver 192.168.11.253
# What to do after installation
# poweroff: SAG pg 13
# halt: SAG pg 8
# reboot: SAG pg 14
poweroff
#
# System Specific Settings
#
# langsupport and keyboard
langsupport --default=en_US en_GB
keyboard us
# System Devices
# Bootloader
# SAG pg 5
bootloader --append="" --location=mbr
# Network information
# SAG pp10-12
#
# SELinux configuration
# Need to add SELinux Policy support through policy modules.
#
selinux --disabled
# System authorization information
# SAG pp 2-5
auth --enablemd5 --enableshadow
# Autoconfigure mouse
# SAG p10
# "mouse" with no options autodetects the mouse
# Optionally, it can have three arguments.
# [--device=ttyS0] [--emulthree] [mousetype]
#
mouse
# Firewall configuration
# SAG p 7
firewall --disabled
# Run the Setup Agent on first boot
# Mode is one of enabled, disabled, reconfig
# SAG pp 7-8
firstboot --disable
#
# Root password
#
# SAG pg 15
rootpw --iscrypted XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# System timezone (set via %pre?)
# timezone: SAG pg16
timezone --utc Australia/Melbourne
# X or no X
# Either "skipx" or "xconfig --startxonboot"
# skipx: SAG p15
skipx
#clearpart --initlabel
# Disk partitioning information
#
# Partition information
# zerombr: SAG p17
zerombr yes
# NOTE - Partition information is generated in the pre scripts
%include "/tmp/partitions.ks"
#
# OS Specific Tags
# Use this section for tags specific to a particular config
#
#entitlement
key bbe5b781bb89f5b6
# Packages
# SAG pp 18-19
# --nobase is documented in various mailing lists. For example,
# http://www.sage.org/lists/sage-members-archive/2006/msg01378.html.
#
%packages --nobase --resolvedeps
aide
at
bc
.
. Lots of packages truncated!
.
yum
yum-utils
zip
#
# Pre-install scripts
# SAG pp 19-21
# Partition information generator
%pre --interpreter=/usr/bin/python
import re
import os
partitions = [['/', 4096, 0, 0],['/boot', 100, 0, 1],['swap', 8192, 0, 0],['/var', 1, 1, 0],['/usr', 8192, 0, 0],['/home', 8192, 0, 0]]
m_ide = re.compile(r'(hd[a-z]):\s+([0-9]+)\s+sectors\s+\(([0-9]+)\sMB\)')
m_scsi = re.compile(r'SCSI\s+device\s+(sd[a-z]):\s+([0-9]+)\s+.*\(([0-9]+)\s+MB\)')
i = dict()
s = dict()
pipe = os.popen('dmesg', 'r')
for line in pipe.readlines():
m = m_ide.search(line)
if m:
i[m.group(1)] = [m.group(2), m.group(3)]
m = m_scsi.search(line)
if m:
s[m.group(1)] = [m.group(2), m.group(3)]
ide_drives = list()
scsi_drives = list()
do_drives = list()
for k in i.keys(): ide_drives.append([k, i[k][0], i[k][1]])
for k in s.keys(): scsi_drives.append([k, s[k][0], s[k][1]])
if (len(ide_drives) > 0):
if ((len(ide_drives) == 2) and ((ide_drives[0][1] == ide_drives[1][1]) and (ide_drives[0][2] == ide_drives[1][2]))): do_drives = ide_drives
else: do_drives = 'hda'
elif (len(scsi_drives) > 0):
if ((len(scsi_drives) == 2) and ((scsi_drives[0][1] == scsi_drives[1][1]) and (scsi_drives[0][2] == scsi_drives[1][2]))): do_drives = scsi_drives
else: do_drives = 'sda'
else: do_drives = 'sda'
pfile = open("/tmp/partitions.ks", "w")
pfile.write("clearpart --all --initlabel --drives=%s\n" % ",".join([x[0] for x in do_drives]))
rstr =
for index, p in enumerate(partitions):
if (len(do_drives) == 2):
pfile.write("partition raid.0%d --size=%d %s %s --ondisk=%s\n" % (index, p[1], ((p[2] == 1) and '--grow' or ), ((p[3] == 1) and '--asprimary' or ), do_drives[0][0]))
pfile.write("partition raid.1%d --size=%d %s %s --ondisk=%s\n" % (index, p[1], ((p[2] == 1) and '--grow' or ), ((p[3] == 1) and '--asprimary' or ), do_drives[1][0]))
rstr += "raid %s --fstype=%s --device=md%d --level 1 raid.0%d raid.1%d\n" % (p[0], ((p[0] == 'swap') and 'swap' or 'ext3'), index, index, index)
else:
pfile.write("partition %s --fstype=%s --size=%d %s %s --ondisk=%s\n" % (p[0], ((p[0] == 'swap') and 'swap' or 'ext3'), p[1], ((p[2] == 1) and '--grow' or ), ((p[3] == 1) and '--asprimary' or ), do_drives[0][0]))
pfile.write(rstr)
pfile.close()
pfile = open("/tmp/partition-script.ks", "w")
if (len(do_drives) == 2):
pfile.write("\n%post\n/sbin/grub << EOF\n")
for d in do_drives:
pfile.write("device (hd0) /dev/%s\nroot (hd0,0)\nsetup (hd0)\n" % d[0])
pfile.write("quit\n")
pfile.write("EOF\n")
pfile.close()
#
# OS Specific Pre Scripts
#
# NOTE - Grub setup, if needed
%include "/tmp/partition-script.ks"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment