32.8. Kickstart Examples

32.8.1. Set host name interactively during installation

The following example demonstrates how to interactively set the system's host name during installation. The %pre script asks to enter a host name for the installed system. The %post script configures the network according to the user's input.
chvt 3
exec </dev/tty3> /dev/tty3
## Query for hostname, then write it to 'network' file
read -p "
What is my hostname (FQDN)? (This will be set on eth0)
" NAME /dev/tty3 2>&1
echo "NETWORKING=yes" > network
echo "HOSTNAME=${NAME}" >> network
echo "DEVICE=eth0" > ifcfg-eth0
echo "BOOTPROTO=dhcp" >> ifcfg-eth0
echo "ONBOOT=yes" >> ifcfg-eth0
echo "DHCP_HOSTNAME=${NAME} " >> ifcfg-eth0
cat ifcfg-eth0
chvt 1
exec < /dev/tty1 > /dev/tty1

%post --nochroot
# bring in hostname collected from %pre, then source it
cp -Rvf network /mnt/sysimage/etc/sysconfig/network
# Set-up eth0 with hostname
cp ifcfg-eth0 /mnt/sysimage/etc/sysconfig/network-scripts/ifcfg-eth0
# force hostname change
/mnt/sysimage/bin/hostname $HOSTNAME

32.8.2. Registering and Then Mounting an NFS Share

Register the system to a Red Hat Subscription Management server (in this example, a local Subscription Asset Manager server):
%post --log=/root/ks-post.log
/usr/sbin/subscription-manager register --username=admin@example.com --password=secret --serverurl=sam-server.example.com --org="Admin Group" --environment="Dev"
Run a script named runme from an NFS share:
mkdir /mnt/temp
mount -o nolock /mnt/temp
openvt -s -w -- /mnt/temp/runme
umount /mnt/temp
NFS file locking is not supported while in kickstart mode, therefore -o nolock is required when mounting an NFS mount.

32.8.3. Registering a System in RHN Classic

The rhnreg_ks command is a utility for registering a system with the Red Hat Network. It is designed to be used in a non-interactive environment (a Kickstart style install, for example). All the information can be specified on the command line or standard input (stdin). This command should be used when you have created an activation key and you want to register a system using a key.
For details about using rhnreg_ks to automatically register your system, see the Knowledgebase article at https://access.redhat.com/solutions/876433.

32.8.4. Running subscription-manager as a Post-Install Script

The subscription-manager command-line script registers a system to a Red Hat Subscription Management server (Customer Portal Subscription Management, Subscription Asset Manager, or CloudForms System Engine). This script can also be used to assign or attach subscriptions automatically to the system that best-match that system.
When registering to the Customer Portal, use the Red Hat network login credentials. When registering to Subscription Asset Manager or CloudForms System Engine, use whatever user account was created by the local administrator.
Additional options can be used with the registration command to set a preferred service level for the system and to restrict updates and errata to a specific operating system version.
%post --log=/root/ks-post.log
/usr/sbin/subscription-manager register --username=admin@example.com --password=secret --serverurl=sam-server.example.com --org="Admin Group" --environment="Dev" --servicelevel=standard --release="6.6"
For additional information about using subscription-manager, see the Knowledgebase article at https://access.redhat.com/solutions/748313.

32.8.5. Changing partition layout

The following example %pre script generates a different set of partitioning commands depending on whether the system has two drives or not.
for file in /proc/ide/h* do
	mymedia=`cat $file/media`
	if [ $mymedia == "disk" ] ; then
		hds="$hds `basename $file`"
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 "zerombr" >> /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
	#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
Adding the following line after the %pre script then instructs Kickstart to execute the commands that were generated by the script above:
%include /tmp/part-include