How to save %pre installation log file after installation in Red Hat 7

We intend to write multiple scripts in the %pre and %post section of the kickstart files as per our requirement but since these scripts are executed in the background it is very important that we perform proper logging of individual section so that once the node is successfully installed those logs can be validated to make sure all the scripts were successfully executed and to debug further in case of failure.

How to enable logging of %pre and %post scripts in kickstart?

Below syntax can be used to enable the logging of individual %pre and %post section in a kickstart file
%pre --log=/var/log/kickstart_pre1.log
echo "Hello World"
echo "This is first pre-installation script"
%end

%pre --log=/var/log/kickstart_pre2.log
echo "Hello World"
echo "This is second pre-installation script"
%end

%post --log=/var/log/kickstart_post1.log
echo "Hello World"
echo "This is first post-installation script"
%end

%post --log=/var/log/kickstart_post1.log
echo "Hello World"
echo "This is second post-installation script"
%end

How to store %pre section logs to be accessible after complete Red Hat Installation?

Now this is the tricky part as all the logs stores for %post section would be accessible after a node is successfully installed but we have to take some extra steps to save the %pre script log files

Since %post section is by default executed in chroot environment write an additional %post script as below to save both your %pre log files we used above

%post --log=/var/log/kickstart_post_3.log --nochroot
echo "Copying %pre installation script log files
/bin/cp -rvf /var/log/kickstart_pre*.log /mnt/sysimage/var/log/
%end
So once your node is successfully installed check "/var/log" for your both the kickstart_pre*.log files and the %post section log files

I hope the article was helpful.