Product SiteDocumentation Site

32.7. Post-installation Script

You have the option of adding commands to run on the system once the installation is complete. This section must be placed towards the end of the kickstart file, after the kickstart commands described in Section 32.4, “Kickstart Options”, and must start with the %post command. If your kickstart file also includes a %pre section, the order of the %pre and %post sections does not matter.
This section is useful for functions such as installing additional software and configuring an additional nameserver.

Note

If you configured the network with static IP information, including a nameserver, you can access the network and resolve IP addresses in the %post section. If you configured the network for DHCP, the /etc/resolv.conf file has not been completed when the installation executes the %post section. You can access the network, but you can not resolve IP addresses. Thus, if you are using DHCP, you must specify IP addresses in the %post section.

Note

The post-install script is run in a chroot environment; therefore, performing tasks such as copying scripts or RPMs from the installation media do not work.
--nochroot
Allows you to specify commands that you would like to run outside of the chroot environment.
The following example copies the file /etc/resolv.conf to the file system that was just installed.
%post --nochroot 
cp /etc/resolv.conf /mnt/sysimage/etc/resolv.conf
--interpreter /usr/bin/python
Allows you to specify a different scripting language, such as Python. Replace /usr/bin/python with the scripting language of your choice.
--log /path/to/logfile
Logs the output of the post-install script. Note that the path of the log file must take into account whether or not you use the --nochroot option. For example, without --nochroot:
%post --log=/root/ks-post.log
with --nochroot:
%post --nochroot --log=/mnt/sysimage/root/ks-post.log

32.7.1. Examples

Example 32.1.  Register the system to a Red Hat Network Satellite and log the output:
%post --log=/root/ks-post.log
wget -O- http://proxy-or-sat.example.com/pub/bootstrap_script | /bin/bash
/usr/sbin/rhnreg_ks --activationkey=<activationkey>

Example 32.2.  Run a script named runme from an NFS share:
mkdir /mnt/temp 
mount -o nolock 10.10.0.2:/usr/new-machines /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.

Example 32.3. Running subscription-manager as a post-install script
Red Hat Enterprise Linux 6 has a command-line tool, subscription-manager, which registers a system to Red Hat's hosted content service and draws down content from that service, according to the subscriptions available to the organization. As with registering a system to a local Satellite service, the subscription-manager tool can be run as a post-install script. The --autosubscribe option automatically subscribes the new system to the best-matched subscription pool available after registering it with the entitlements service.
%post --log=/root/ks-post.log
/usr/sbin/subscription-manager register --username rhn_username --password rhn_password --autosubscribe