Saturday, March 10, 2012

Basic PXE Install Server

Basic TFTP PXE DHCP Setup in Redhat 6 and CentOS 6

In order to prepare a Normal PXE Server we need the following Servers and Services to be set up prior to proceeding further.

  • Install NFS, FTP, HTTP and related packages.
  • Install TFTP Server and related Packages
  • Install DHCP Server and related Packages

Setting up the Network Server  [ NFS | FTP | HTTP ]

First, configure an NFS, FTP, or HTTP server to export the entire installation tree for the version and variant of Linux to be installed.

We are going to use NFS simply because there are fewer steps involved. You are free to use any server to your liking, infact I recommend to install all the Servers and see for your self.

[] # yum install nfs-utils*
[] # chkconfig portmap on
[] # chkconfig nfs on
[] # service portmap restart
[] # service nfs restart

Create a directory /Linix_Distros/Osdir and dump the contents of the Linux DVD / Linux CD’s in that directory. And export the directory of /Linux_Distros to your local Network

Your /etc/exports file should look like this.

Terminal Window View
[] # cat /etc/exports
/Linux_Distros  *,sync)

Setting up the TFTP Server and related packages

Install the TFTP server and the related packages with the following commands.

[] # yum install tftp*

Before we move on we need to configure the tftp-server so that it will be started when the the system boots. First of all we need to enable the tftp-server so that its running in the first place. To do this we need to go to /etc/xinetd.d/tftp file and change the disable=yes to disable=no and then restart the xinetd service. Just check the following to see how to do that.

Terminal Window View
[] # cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol.  The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
 socket_type  = dgram
 protocol  = udp
 wait   = yes
 user   = root
 server   = /usr/sbin/in.tftpd
 server_args  = -s /tftpboot
 #change the following to 'no'
 #disable  = yes
 disable          = no
 per_source  = 11
 cps   = 100 2
 flags   = IPv4

Then restart the xinetd service.

[] # chkconfig --levels 35 xinetd on
[] # service xinetd restart

Create a directory /tftpboot and under it create another directory pxelinux.cfg so the path looks like this
/tftpboot/pxelinux.cfg for clarity look to the following.

[] # mkdir -p /tftpboot/pxelinux.cfg

You will need to find the vmlinuz and initrd.img files in the /Linux_Distros/Osdir directory and copy them into the /tftpboot directory. These files will be used to start the kickstart process after the PXE boot has taken place.

Suppose we have a Red Hat Enterprise Linux™ 5 installation then my path should be /Linux_Distros/RHEL5 and I would find the vmlinuz and initrd.img in the following locations /Linux_Distros/RHEL5/images/pxeboot

Please note that the vmlinuz kernel must match the version of OS you are going to build.
[] # cp /Linux_Distros/RHEL5/images/pxeboot/initrd.img\
[] # cp /Linux_Distros/RHEL5/images/pxeboot/vmlinuz\

Booting a PC without a kernel written to a disk requires the use of PXE boot. And this can be achieved by installing the syslinux package. This package if not installed,  install it with the following command.

[] # yum install syslinux*

The component that is needed from this package to perform a PXE boot is pxelinux.0   Run a search for this file under the entire / directory. Once found copy the file to /tftpboot.

[] # cp /var/lib/syslinux/pxelinux.0 /tftpboot

Setting up the DHCP Server and related packages

Install a DHCP server that allows bootp onto the Linux Server. If a compatible DHCP package cannot be found on the installation disks, one can be downloaded at

The installation of the DHCP server should create an example of /etc/dhcpd.conf. The dhcpd.conf file is configuration file for the DHCP server. Rename this file and create a new one with the same name.  For the sake of your convinience I have provided one below.

Terminal Window View
ddns-update-style none;
ignore client-updates;

option domain-name  "";
option domain-name-servers;
default-lease-time 21600;
max-lease-time 43200;

########## IMPORTANT FOR PXE BOOTING ###############
allow booting;
allow bootp;

subnet netmask {

# --- default gateway
option routers;
option subnet-mask;

########## VERY IMPORTANT FOR PXE BOOTING ##########
filename "pxelinux.0"; 
########## IMPORTANT FOR PXE BOOTING ###############

Create a Kickstart File

You can create a Kickstart file from the system-config-kickstart if your are using Redhat or Fedora. Create a Kickstart file and name it ks.cfg or alternatively you can rename the anaconda-ks.cfg found in your root directory as a template for your ongoing installations.

Make the ks.cfg available though FTP,HTTP or NFS. For this we will use NFS and make it available through the /Linix_Distros directory since its exported already.

Once the client machine obtains the PXE environment specified in the dhcpd.conf file it begins to make tftp requests for a file named after its’ IP address in uppercase hexadecimal format. The hexadecimal file needs to be contained in the /tftpboot/pxelinux.cfg directory.

For example: The IP that was used for this document was The file that the machine then requested was /tftpboot/pxelinux.cfg/C0A80219 .

Incase you have not configured dhcp entries for each station in your network the pxelinux environment looks for a default file located in the /tftpboot/pxelinux.cfg/default. Create one to avoid confusion.

It should contain the following

Terminal Window View
[] # cat /tftpboot/pxelinux.cfg/default
default ks
prompt 0
timeout 600
label ks
kernel vmlinuz
append ks=nfs: initrd=initrd.img

Once the kernel is loaded an nfs mount is performed and the kickstart information is pulled from the specified the location.

CONGRATULATIONS you have now configured a TFTP,DHCP,NFS PXE Server to distibute the OS to a wide range of clients simultaneously, for unattended installations.

No comments:

Post a Comment