Tuesday, July 27, 2010

Building a Kickstart Install Server (CentOS/Redhat)

In a recent project I needed to build a kickstart server which would be used to automate the deployment of some new servers that were being setup.  We will build a simple kickstart server offering installs over HTTP to the clients.  I will also post a sample kickstart script that I used to accomplish the installs of the servers.  This little project actually turned out to be quiet easy, and the most difficult part was writing the custom scripts to execute after the installation of the server completed.  First we are going to install/setup the kickstart server itself.  I will be using Virtualbox as my test environment to demonstrate here.  Using the CentOS install DVD, walk through the install instructions to get the system up and running.  This should be fairly simple although I will make one note; I only install the base packages and the Gnome desktop manager to keep the install quick and easy.  If you'd like to add other packages to your install just be aware that it can raise the amount of time that the install takes (my install time was about 10 minutes).  After the installation of the server is complete you will be brought to the desktop for the first time.  When performing network installations with kickstart you can actually offer up the install files via NFS, HTTP, or FTP.  I choose to use HTTP because it was the quickest and slightly easier than the other two methods.  It also requires less configuration for those attempting this for the first time.

While you don't need Gnome in order for this server to work properly it is easier to use and saves time in the configuration aspects.  Once you have a desktop go to System -> Administration -> Security Level & Firewall.  Here you can make changes to SELinux and the Firewall.  First we will need to check off the boxes for NFS, SSH, and HTTP (don't disable the firewall unless you are in a totally isolated environment).  In the second tab change the SELinux setting to permissive or disabled (I choose disabled because I have no need for it on this server).  Confirm all the changes and allow the settings to take effect.  Next we will need to install Apache which will serve up the installation files.  Open a shell, change to the root user, and install Apache with: yum install httpd.  Once the install has completed verify that the service is running with: service httpd status.  The last part of the configuration will be to create the directory structure we will use to serve the installation files and populate them.  You will need to make sure that the install DVD for CentOS is in the CD-ROM drive.  In the same shell use the following commands to create directories and copy over the files for installation.

cd /var/www
mkdir pub
cd pub
mkdir kickstart
cp -vr /media/CentOS_5.4_Final/ /var/www/pub/

You should now have a pub directory that is filled with the install files from the CentOS 5.4 install DVD, which will be used to install clients via kickstart.  For the last steps we will need to build a kickstart file and copy it into /var/www/pub/kickstart where the clients will pull it from during install.  Below I will paste a basic kickstart files (with comments) that you can copy & paste into a file called test.cfg, which will need to be moved to /var/www/pub/kickstart.  Kickstart files can get very complex with scripts and custom settings which is why we are going to use this basic template.

# Kickstart file for a basic install.

install
url --url http://192.168.1.100/pub/
lang en_US.UTF-8
keyboard us

# Assign the client a static IP upon first boot & set the hostname
network --device eth0 --bootproto static --ip=192.168.1.105 --netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=192.168.1.1 --hostname RHEL01 --noipv6

# Set the root password
rootpw --iscrypted

# Enable the firewall and open port 22 for SSH remote administration
firewall --enabled --port=22:tcp

# Setup security and SELinux levels
authconfig --enableshadow --enablemd5
selinux --permissive

# Set the timezone
timezone --utc America/New_York

# Create the bootloader in the MBR with drive sda being the drive to install it on
bootloader --location=mbr --driveorder=hda

# Wipe all partitions and build them with the info below
# ***hda may be different on your machine depending on the type of drives you use***
clearpart --drives=hda --all --initlabel
part /boot --fstype ext3 --size=100
part / --fstype ext3 --size=5000
part swap --size=2000
part /home --fstype ext3 --size=100 --grow

# Install the Base and Core software package groups for a minimal install, plus OpenSSH server & client
%packages
@Core
@Base
openssh-clients
openssh-server

Now everything is in place.  The kickstart server has been built, the kickstart file is in place, and you are ready to boot up your client to start testing a kickstart installation.  For our test we will kick off another virtual machine and boot from the netinstall.iso (available from the CentOS downloads page).  This will boot off the CD and give us a prompt for parameters to be passed to the kernel during boot up.  We will use the following command:

$ linux text ks=http://192.168.1.100/pub/kickstart/test.cfg append ip=192.168.1.105 netmask=255.255.255.0

This command tells the client to boot the kernel, look for the 192.168.1.100 server (our kickstart server), retrieve the test.cfg file from /pub/kickstart/, and assign the client a static address of 192.168.1.105.  There are two things to note here; one is that in order to not use a static address you will need a functional DHCPserver with specific settings configure (this will be detailed in another post), two the static ip assignment can actually take place in the kickstart file however there is a bug in CentOS currently which prevents this from happening, which is why we must specify a static ip via kernel boot parameters.  If you typed the command correctly and the server is setup properly you will see the client begin to install the system automatically.  When finished you will be prompted to reboot and your system will be ready for use!  While the install is happening you can view log files in the background by switching virtual terminals.  Alt+F2 will give you a shell once the system is installed, Alt+F3 will show command line logs, Alt+F4 shows the kernel logs.  This process to automatically install servers and clients via kickstart is extremely helpful in rolling out new systems and fairly easy to accomplish.  Hopefully you will take this further and work on customizing your installations and post install scripts.  For a reference on kickstart files see the documentation:

http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-kickstart2-options.html

For a more automated approach to kickstart check out my other posting for PXE booting, hands free install: