In a previous post, I described how to automatically install a CentOS system with the help of Kickstart. In that post, I provided a link to the Kickstart file I used back then. It is truly automatic, including the network configurations. However, sometimes we may want to manually configure certain things, e.g. the network, while performing an “automated” installation. In this post, I use network as an example to demonstrate how to configure things manually during a Kickstart installation.
In Kickstart, there are two things that enables such possibility. The first thing is
This is a directive in Kickstart files to include Kickstart configurations from another file. It means that if we could somehow generate that file based on our manual input during the installation process, we achieve manual configuration in a Kickstart install.
%pre is exactly what we need for this task.
%pre, together with its corresponding
%end, define a segment of shell script to be executed before Kickstart begins the installation phase.
%pre #!/bin/sh echo test > /tmp/foo.ks %end
We could write a few lines to ask for user input and store the information in the file we specify on the
The manual network configuration script
Below is the actual script that I personally use for manually configuring network interfaces. We are switching to
tty6 here because Kickstart uses the first few
ttys. To find out all network interfaces available on the system, I check the
/sys/class/net directory. Notice that the loopback interface
lo is also in there and you do not want to configure it manually!
# ask the user for network information %pre #!/bin/sh exec < /dev/tty6 > /dev/tty6 2> /dev/tty6 chvt 6 NETWORK_INTERFACES=$(ls /sys/class/net) for NET in $NETWORK_INTERFACES; do # skip loopback interface if [ "$NET" = "lo" ]; then continue fi echo "======= Configuring for $NET =======" echo -n "Do you want to configure this interface? [y/n] " read YN if [ "$YN" != "y" ]; then continue fi echo -n "Configure as static (default is DHCP)? [y/n] " read YN if [ "$YN" = "y" ]; then read -p "Enter IP address: " IP_ADDR read -p "Enter netmask: " NETMASK echo "network --bootproto=static --device=$NET --onboot=yes --ip=$IP_ADDR --netmask=$NETMASK" >> /tmp/network.ks else echo "network --bootproto=dhcp --device=$NET --onboot=yes" >> /tmp/network.ks fi done chvt 1 exec < /dev/tty1 > /dev/tty1 2> /dev/tty1 %end
In conclusion, I described what enables us to perform manual configuration during an “automated” Kickstart installation. I also included my own script for manually configuring the network interfaces. This could be served as an example for your own scripts.