Executing an external script during pre installation of kicstart

Latest response

Hi all,

I'm trying to configure a kicstart + PXE server for a large deployment of servers with over 100 network segments.
What I would like to achieve is that the user will choose at the PXE menu the required OS type (i.e RHEL, Ubuntu, etc) and version (i.e. RHEL 6.3, RHEL 5.8, etc) and this will initiate a kickstart installation process, during which a pre installation script will run and ask for certain network settings.

So far, I have PXE and kickstart configured but I cannot get the pre installation part to work according to my needs.
Initially I entered the code to the %pre section, including moving the user between consoles (exec and chat commands) and tested it. That worked.
Here is what I had in %pre:

%pre

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

!/bin/sh

echo "Please select a network segmant from the following list:"
echo "1. VLAN 01"
echo "2. VLAN 02"
****Additional Networks****

echo -n "Network: "
read SEGMENT
case ${SEGMENT} in
1)
SUBNET="255.255.255.0"
GATEWAY="X.X.X.X"
DNS="X.X.X.X,X.X.X.X"
;;
2)
SUBNET="255.255.255.0"
GATEWAY="X.X.X.X"
DNS="X.X.X.X,X.X.X.X"
;;
****Additional Networks****
30)
SUBNET="255.255.255.0"
GATEWAY="X.X.X.X"
DNS="X.X.X.X,X.X.X.X" ;;
;;
esac

echo -n "Please provide IP Address: "
read IP

clear
echo -n "Please provide a hostname for this server: "
read HOST

echo "network --device=eth0 --bootproto=static --ip=${IP} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=${HOST} --onboot=yes --noipv6" > /tmp/network-include

chvt 1
exec < /dev/tty1 > /dev/tty1 2> /dev/tty1

However, since I want to support multiple OS types and versions and multiple network segments, including the ability to seamlessly add versions and networks in the future, I wanted to direct the kickstart file to run a script during pre installation phase.

This I could not get to work.

I tried putting the script on an NFS share, mounting the share in %pre and running it in %pre.
The script runs but the last chvt command fails with an error message of "command not found" and fails the entire installation process.
This is my current %pre configuration:
%pre

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

!/bin/sh

mount -t nfs :/location/of/script /mnt
/mnt/script.sh

chvt 1
exec < /dev/tty1 > /dev/tty1 2> /dev/tty1

I could not understand why I get this message, as it appears exactly where it was when all the network configuration code was hard coded in the kickstart file.

Any help with this issue or advices regarding different approaches to this requirement would be much appreciated.
Thanks,
Yair

Responses

Hello Yair -
When attaching code to your post, you can start/end the code segment with 3 x tilde's "~~~"

Now - on to your question ;-)
Have you considered having the menu presented during PXE? I.e. in your msgs/boot.menu and your default file?

  • Sorry that I can't answer your question directly.

Hi James,

Thanks for replying and your update regarding the code format, I will make sure to use it.

I have thought about using the PXE menus to achieve my goal but that would mean having as many menus as the amount of networks times the OS versions I have. And that's a lot.
Unless there's a method to dynamically create menus which I'm not aware of.

Yair

There are several ways you could approach this. In my case, I manually build my PXE/tftp/DHCP server (i.e. I don't have a packaged application). I only have to modify 2 files
/var/lib/tftpboot/pxelinux.cfg/default
/var/lib/tftpboot/msgs/boot.menu

The boot.menu file is somewhat ambiguous. As long as whatever string the user types in exists in the default file, I'm good. I have done some "automation" at times to recreate my default file to include several different options.

So - my menu includes entries to allow an interactive experience
rhel6
rhel7
then I have an entry for every hostname in my environment, which will find a matching kickstart profile in a web directory.

Unfortunately I think this would be a great conversation in-person, but tough to do via the portal - as there are simply soooo many different ways to approach this.

Excellent how can we communicate personally?

Hi all,

For future references - if anyone happens to have this issue - the way to avoid this issue is to perform the mount in such a way that the mount point is under /tmp.
instead of performing this:

mount -t nfs nfs_server_IP:/location/of/script /mnt

do this:

mkdir /tmp/mnt && mount -t nfs nfs_server_IP:/location/of/script /tmp/mnt

Apparently, my mistake was to mount the NFS share outside the scope of the kickstart environment which caused all sorts of issues.

James - thanks for your help on this issue

Yair