Product SiteDocumentation Site

A.14. %post (optional) - Post-installation Script

You have the option of adding commands to run on the system once the installation is complete, but before the system is rebooted for the first time. This section must be placed towards the end of the Kickstart file, after the actual Kickstart commands, and must start with %post and end with %end. 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 or configuring an additional name server. The post-install script is run in a chroot environment, therefore, performing tasks such as copying scripts or RPM packages from the installation media do not work by default. You can change this behavior using the --nochroot option as described below.


If you configured the network with static IP information, including a name server, 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 cannot resolve IP addresses. Thus, if you are using DHCP, you must specify IP addresses in the %post section.
The following options can be used to change the behavior of post-installation scripts. To use an option, append it to the %post line at the beginning of the script. For example:
%post --interpreter=/usr/bin/python
--- Python script omitted --
Allows you to specify a different scripting language, such as Python. For example:
%post --interpreter=/usr/bin/python
Any scripting language available on the system can be used; in most cases, these will be /usr/bin/sh, /usr/bin/bash, and /usr/bin/python.
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
Display an error and halt the installation if the script fails. The error message will direct you to where the cause of the failure is logged.
Logs the script's output into the specified log file. 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
For an example of a post-installation script, see Section A.15.3, “Example Post-installation Script”.