Interactive pre-/post-install scripts in RedHat KickStart

RedHat Enterprise Linux, Fedora, CentOS and similar systems can be auto-installed using KickStart scripts. Unfortunately the KickStart concept is not designed to conveniently interact with the operator. One of the most Frequently Asked Questions about KickStart is “How do I enter a hostname and IP address during installation?” That’s indeed a common and valid question but there’s no well known answer.

If you’re in position to install dozens of RedHat machines, perhaps a classroom full of workstations, you will probably look at using a customised DVD with a kickstart file tuned to your needs. In such a case you want all the machines be exactly the same, except for their hostname and IP address. Sure, you can use DHCP to set both, but in some cases that’s not possible. It may be better to ask for the hostname and IP during installation. How to do that?

KickStart supports custom pre-install and post-install scripts, but normally doesn’t let the user see the output or enter any input. But it is possible to do that:

# Install in text mode.
[... all the other kickstart settings ...]

# Pre-install script — beware that at this point
# the system is not yet installed and the target
# filesystem may not yet be created. That means
# you can't yet do any changes to it!

# This is the trick — automatically switch to 6th console
# and redirect all input/output
exec < /dev/tty6 > /dev/tty6 2> /dev/tty6
chvt 6

# We can break into a shell prompt

# Or even run a python script
python << __EOF__
# Any other Python code can come here
print "This is pre-install shell"

# Then switch back to Anaconda on the first console
chvt 1
exec < /dev/tty1 > /dev/tty1 2> /dev/tty1

# Same chvt/exec magic as above
# Post-install by default runs chrooted in the just installed system,
# feel free to ask for hostname and IP address and update the system files ;-) 

Just bear in mind that at the moment the pre-install script runs the target filesystem is not yet available and you therefore can’t customise it. Wait for post-install to do that ;-)

That’s about it. Once your pre/post script gains control over the 6th console you can do whatever you like, ask some questions, or at least see the output of your commands. Even that is a huge convenience improvement!

5 thoughts on “Interactive pre-/post-install scripts in RedHat KickStart

  1. Pingback: Getting to a Shell Prompt to Debug Kickstart / Preseeding issues in Ubuntu at Jacob J. Walker's Blog

  2. Jacob J. Walker

    I really appreciate this post, and I want to ask for some of this information up front in the %pre script so I can use it later on in my %post script. But when I set environmental variables in the %pre script, they don’t seem to be continuing to the end, and if I create a temp file with some of this data, the %post script is in a chroot environment (which I need), and so I can’t seem to get the files from before (unless I can find a way to mount the original environment?) Do you have any thoughts on solving this problem? I really appreciate any thoughts you may have!

    1. Michael Ludvig Post author

      Hi Jacob. Why don’t you ask the questions at the beginning of %post instead? I’m not aware of an easy way to pass info from %pre to %post – they run in different shells, with different root. It may be doable with some fs-mounting hackery but easier just to ask in %post I guess…

      1. Jacob J. Walker

        Thanks for your thoughts, and that technical info will help me to not to go down some wrong paths. I want to have questions in the %pre section, because I’m trying to have my installation being as “hands-free” as possible, so I would really like to ask any questions that need to be asked up front, and then just to be able to leave the machine and come back later and know it is done.

        I am going to explore to see if there is a way to access files outside of the chroot that happens in the %post portion of the script. I still want to have the chroot, as it simplifies so much of my %post installation, but maybe there is some command or utility that will allow me to see the original file system, which I’m assuming is some form of Ramdisk (Maybe squashfs?), and see if I can store the variables in a file in the %pre script and grab them in the %post script.

        1. Jacob J. Walker

          I just wanted to give you an update. I figured out how to pass variables from the %pre script to the %post script using a ram disk, and I posted my solution at:

          I just want to say thank you again for your post to make the script interactive. This has been extremely valuable to the VubuntuBox distro that I’m working on!!!!


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>