As of this writing, I'm just finishing up the process of setting up a PXE booting kickstart server (which I'm planning on doing a full writeup on soon). After getting everything working, in terms of bare metal to installed OS, I got to the point of starting to tweak my kickstart configs. And when I wanted to set up the network info on the newly created OS, I ran into a snag.
At my current job, we have a few Red Hat/CentOS servers scattered about, but we are mostly a FreeBSD shop. We already had a home-brewed PXE boot installer for FreeBSD that was originally cobbled together years ago, but after a recent merger we were starting to hear whispers of having to build out more RH/CentOS, so I figured I would hop on this mission as I was by far the best “Linux guy” we had. Being that our FreeBSD installer was home-brewed, it was generally pretty simple to add in new functionality, as the install system was just a bunch of shell scripts. I had built an interactive menu into this system for configuring the network after the install quite some time ago, and I wanted to do the same thing with this new kickstart box for RH/CentOS.
I noticed in initial testing that anything I was trying to output to the terminal in the
%post section of the kickstart file was not showing up, but that I was able to read from the terminal. After doing a little searching, I found this post that gave me the jumpstart I needed to get this all straightened out. The problem I had was that though the example would work just fine for when we are standing at the machine with a crash cart, I also had configs set up to do the installs over a serial console. That example just wouldn't work for that situation.
For the purposes of brevity, I'm going to assume you are already familiar with the kickstart system, have a server, etc. I'm just going to cover the interactive input in the
%post section of the kickstart file.
I'm not going to waste much time here, but just jump in and get to the code.
%post hostname="" ip="" netmask="" gw="" opts="" answer="n" device="eth0" hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'` dns1="126.96.36.199" dns2="188.8.131.52" curTTY=`tty` exec < $curTTY > $curTTY 2> $curTTY clear while [ x"$answer" != "xy" ] && [ x"$answer" != "xY" ] ; do echo -n "enter hostname: "; read hostname echo -n "enter ip: "; read ip echo -n "enter netmask: "; read netmask echo -n "enter default gw: "; read gw echo -n "hard set '100baseTX full-dulplex' [y/n] " ; read opts echo echo You entered: echo -e "\thostname: $hostname" echo -e "\tip: $ip" echo -e "\tnetmask: $netmask" echo -e "\tdefault gw: $gw" echo -e "\tset 100baseTX full-duplex: $opts" echo -n "Is this correct? [y/n] "; read answer done if [ x"$opts" = "xy" ] ; then opts="speed 100 duplex full autoneg off" else opts="" fi sed -i -e 's#^\(HOSTNAME=\).*$#\1'"$hostname"'#' /etc/sysconfig/network echo GATEWAY=$gw >> /etc/sysconfig/network echo DEVICE=$device > $scrFile echo BOOTPROTO=static >> $scrFile echo ONBOOT=yes >> $scrFile echo NM_CONTROLLED=no >> $scrFile echo HWADDR=$hwaddr >> $scrFile echo IPADDR=$ip >> $scrFile echo NETMASK=$netmask >> $scrFile echo USERCTL=no >> $scrFile echo DNS1=$dns1 >> $scrFile echo DNS2=$dns2 >> $scrFile if [ "x$opts" != "x" ] ; then echo 'ETHTOOL_OPTS="'"$opts"'"' >> $scrFile fi %end
As you can see, there's nothing really fancy about this simple shell based menu (which you can definitely expand upon). The real points of interest here are in these lines:
curTTY=`tty` exec < $curTTY > $curTTY 2> $curTTY clear
First, we are setting the
curTTY variable to what our current terminal is. In the next line we are explicitly setting this scripts I/O to the tty's standard descriptors. And finally, in the 3rd line, we just clear the terminal window for a fresh start.
This is really where we end up with a better solution than the example I originally found since we are using our current tty, whatever it is, to interact with you.
I hope this helps someone else out in the future. As I mentioned at the beginning of this article, I will also be writing a full tutorial on setting up a kickstart PXE server soon.