By charlie, Wed, 06/10/2009 - 00:41
The %pre section is where you can specify commands to run before the system is installed. Commands placed here are not run in the chrooted install environment. %pre must come at the end of the kickstart file. You may append --interpreter to the %pre line to have the pre script run a different interpreter than /bin/sh

%include

using a %include can be very helpful. However, you should note that many of the utilities you expect to be on the system will not be present at this point. Moreover, dns will not be operational at ths point. In our example we used nslookup to determine the hostname, you should note that this is not the nslookup that will be on the installed system, it is the busybox nslookup. The output from nslookup in the install environment will be different than that of the full system. To help write your scripts, create a kickstart that has a read line %pre, then chvt to vt 2 (Ctrl-Alt-F2) and try your scripts from the install environment. You will then know which commands are available and more importantly how they will interact with your script.
A problem I have run into when deploying many different machines using kickstart is that the logical volume (lvm) information is the same on all the disks. It becomes a real pain if you want to move drives around (between machines). Since the names of the volgroups are the same, lvm gets confused. To fix this, I use the %include syntax and have the %pre script output the logical volume information.

%include can be used to include any other kickstart script in a kickstart script, so you can modularize your kickstart configs.

In this example, I added %include /tmp/disk.cfg in our default.cfg at the point where we specified the partition information.

...
# Disk partitioning information
part /boot --bytes-per-inode=4096 --fstype="ext3" --size=150
part pv.1 --bytes-per-inode=4096 --grow --size=0
%include /tmp/disk.cfg
...
%pre
IPADDRESS=`ifconfig eth0 |grep 'inet addr' |awk -F: '{print $2 }' |awk '{print $1 }'`
HOSTNAME=`nslookup $IPADDRESS| grep Name | tail -1 | awk '{print $2}'`
HOST=`echo $HOSTNAME |awk -F. '{print $1}'`
if [ "$HOST" = "" ]; then
        HOST="unconfigured"
fi
chvt 2
echo "appending ${HOST}_volume partition information to kickstart" 
cat /tmp/disk.cfg
volgroup ${HOST}_volume --pesize 32768 pv.1
logvol swap --fstype swap --name=SwapVol --vgname=${HOST}_volume --size=1024 --grow --maxsize=8192
logvol / --fstype ext3 --name=RootVol --vgname=${HOST}_volume --size=8192 --grow
EOF
sleep 5
chvt 1
This code will try and configure the volgroup to use the name hostname_volume. If it fails to find the hostname (dns does not work in a %pre script), it will default to using the name unconfigured_volume.