28.6.1. Example

28.6.1. Example

Here is an example %pre section:

%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-includ   
	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

This script determines the number of hard drives in the system and writes a text file with a different partitioning scheme depending on whether it has one or two drives. Instead of having a set of partitioning commands in the kickstart file, include the line:

%include /tmp/part-include

The partitioning commands selected in the script are used.

Note

The pre-installation script section of kickstart cannot manage multiple install trees or source media. This information must be included for each created ks.cfg file, as the pre-installation script occurs during the second stage of the installation process.


Note: This documentation is provided {and copyrighted} by Red Hat®, Inc. and is released via the Open Publication License. The copyright holder has added the further requirement that Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. The CentOS project redistributes these original works (in their unmodified form) as a reference for CentOS-5 because CentOS-5 is built from publicly available, open source SRPMS. The documentation is unmodified to be compliant with upstream distribution policy. Neither CentOS-5 nor the CentOS Project are in any way affiliated with or sponsored by Red Hat®, Inc.