-   Linux - Server (
-   -   kickstart - asking for configuration in the %pre section (

johnnymta 08-16-2009 02:51 AM

kickstart - asking for configuration in the %pre section
Hi guys!

First post here, be nice... :newbie:

I am preparing a kickstart for CentOS 5.3 in my company, and we want to be able to install the product the same way in several servers, but some parameters will vary between different customers we'll ship the product to - for example the root password, or some inner product-related parameters.

One way to solve this is to just burn a new CD with a new configuration file in it for each customer installing our product, but this is a little pain if we're going to ship CDs to 5 different customers every day. It would be much better if in the pre-installation i could ask some questions and process the answers later in the post installation.

I tried to do something like that:

chvt 2
exec </dev/tty2 1>/dev/tty2 2>/mnt/sysimage/root/ks-preinstall-errors.log

echo "-- Passowrd configuration --"
stty -echo

while [ "$ROOTPW" == "" ]; do

    echo -n "Enter desired root password: "
    read rootpw
    echo -n "Confirm password: "
    root rootpw2
    if [ "$rootpw" == "$rootpw2" ]; then
        echo "Passwords do not match! Try again..."

echo "ROOTPW=$ROOTPW" > /tmp/answers.txt

stty echo

chvt 6
exec </dev/tty6 1>/dev/tty6

of course there are some other arguments, and then i do something like

. /tmp/answers.txt
in the %post --nochroot and continue from there...

Anyhow, this doesn't really work - the 'chvt 2' changes to tty2, but doesn't write or gets input from user, and the pre install script just goes on.
Looking at the /tmp/anaconda.log during installation shows the message:
ERROR : Error code 1 encountered running a kickstart %pre/%post script

Anybody has an idea how to fix this?

Thank you very much!

kbp 08-16-2009 10:57 AM

Hi johnymta,

I think anaconda has already allocated tty2 for use and its not interactive, you need to choose an unused one like tty6


exec < /dev/tty6 > /dev/tty6
chvt 6

# prompt user for info here

chvt 1



aviso 08-16-2009 02:51 PM

I tried something like this a while ago and remember something where the input and output weren't on the terminals you expected, so I wond up having to redirect them with >>. I don't think I still have that code, but if I find it, I'll post what I did.

I actually dropped this approach and instead set everything in the kickstart file for generic value and then wrote scripts that ran on firstboot to configure the server. The benefit of this was I could configure everything at once and then still had the scripts available in case someone fat-fingered something.

I've seen where other people pregenerate kickstart files on another server, then select that file for the build. This of course requires you to configure the network, easiest way is with dhcp.

johnnymta 08-17-2009 04:29 AM

Thanks for the answers, However - It actually didn't help... I tried severals ttys, and tried to switch between graphical and text mode - doesn't help...

I think the key issue here might be the error in the log:

ERROR : Error code 1 encountered running a kickstart %pre/%post script

What does error code 1 means?
I think after the chvt command there's an error and the rest of the %pre script doesn't actually work...

This is very frustrating...

The firstboot solution will probably work fine - but then the installation of the system couldn't be really unattended enough (in the case configuration is done at the %pre stage you can go have lunch after that and come back with a fully configured system...)

aviso 08-17-2009 10:31 AM

I found what I had. And as I said, I didn't wind up using this in the end, but you should be able to add something like this to %pre:

clear >/dev/tty1
echo >/dev/tty1
echo -n "Server Name: " >/dev/tty1
echo -n "IP Address: " >/dev/tty1

Then you should be able to reference everything with $SERVERNAME. $IPADDRESS, etc. At least in %pre. Then you can commit whatever else you need to a file.

If you find you need more flexibility than standard shell scripts allow, you might try using python, which should already be in the build environment or miniperl, which you can compile and then dump in a separate directory on the disk.

johnnymta 08-18-2009 02:15 AM

Thanks a lot! This helps a little... I'm close to finding what really was my problem (I have a theory).

BTW, if you don't know - if you want to configure only hostname and IP you can do it by using 'bootproto=query' in the 'network' configuration in the kickstart file...

johnnymta 08-18-2009 02:34 AM

As I thought...
'2>/mnt/sysimage/root/ks-preinstall-errors.log' was the problem...

maybe this is because system is readonly at the %pre section or something...

Or maybe it was the 'clear' command that helped?

I wish anaconda will give a more detailed log in the case of such errors...

simply doing
'exec </dev/tty8 >/dev/tty8' instead of what i wrote at the beginning solved the problem...

Thanks for your help guys! :)

aviso 08-18-2009 04:22 AM

Glad you got it working.

I think '2>/mnt/sysimage/root/ks-preinstall-errors.log' failed because sysimage wouldn't be mounted at this point. If you want to log errors, you'll have to save it somewhere else, such as /tmp/ which sits in RAM and then copy it over during %post.

All times are GMT -5. The time now is 04:02 PM.