Redhat Chroot Kickstart – Execute Half of %Post Section in Nochroot and Other Half in Chroot Environment

chrootkickstartredhat

I am trying to execute a script that performs certain security configurations on my recently installed system. Much of the script refers to files starting with / as the base directory which presents a problem as copying the script from my isolinux directory requires a nochroot environment where the base directory is /mnt/sysimage/. So, is it possible to copy the script over to the correct directory in the nochroot environment, but then once its there switch back to a chroot environment?

For reference, here is what the kickstart's %post section roughly looks like:

%post --nochroot --logfile=/mnt/sysimage/root/ks-post.log
cp /run/install/repo/<script.sh> /mnt/sysimage/root/
---> Here is where I want to switch back to a chroot environment
sh /root/script.sh
%end

Note that I changed the last line from what it currently is, sh /mnt/sysimage/root/script.sh, to reflect the way I want my %post section to look.

Best Answer

%post --nochroot --logfile=/mnt/sysimage/root/ks-post.log
cp /run/install/repo/script.sh /mnt/sysimage/root/
chroot /mnt/sysimage/ /bin/sh /root/script.sh
%end