How to configure PXE boot server in Linux using Red Hat 6

How to configure PXE boot server in Linux using Red Hat 6

PXE is an abbreviation for Preboot eXecution Environment which describes a client server standardized environment to boot from a network a software assembly on a client i.e. an Operating System. It is also pronounced as "pixie" and is mostly used to boot the client machine with a installation media stored on the PXE server using network interface.

In this article I will show you step by step guide to configure a PXE boot server using http and ftp in which you can use either one suiting your requirement.

I will be using Red Hat Linux 6 (32-bit) for my purpose

Server IP: 192.168.1.6

 

Pre-requisites

  • dhcp
  • tftp-server
  • syslinux
  • http/ftp (any one)

Install the required packages using yum

# yum -y install dhcp tftp-server syslinux http ftp vsftpd

 

Prepare installation media on PXE server

Next we need to copy all the files from the installation media(CD/DVD,ISO) to our PXE server.

You can also mount the media file on the PXE server in case you don't want to copy all the files but using that way you will only be able to configure your PXE server for one OS. For configuring multiple OS you will have to copy the OS files into separate directory for different OS.

In my case I want to confiure a PXE server to install CentOS 6.2

Let us create separate directory to save all the installation files

# mkdir -p /var/lib/tftpboot/images/centos/6/i386/
# mkdir -p /var/lib/tftpboot/images/centos/6/x86_64/

Next copy the installation files from the installation media.If you have iso images of the OS you can use WinSCP(on windows) to copy all the files. If the image is mounted on your Linux machine then you can copy using scp command.

To skip the lenghty process as of now we will just mount the dvd to relevant destination.

# mount /dev/sr0 /var/lib/tftpboot/images/centos/6/i386/

mount: block device /dev/sr0 is write-protected, mounting read-only
NOTE: In my case the cdrom is mounted on /dev/sr0 which can be different for you.

 

Configure HTTP/FTP server

You can use either of the mentioned servers for your purpose. But I will show you the configuration of all three so that you can choose any one as per your requirement.

HTTP server

# vi /etc/httpd/conf/httpd.conf
## At the end of the file add the following lines
<VirtualHost 192.168.1.6:80>
    ServerAdmin root@test.example.com
    DocumentRoot /var/lib/tftpboot/images
    ServerName test.example.com
    ErrorLog logs/test.example.com-error_log
    CustomLog logs/test.example.com-access_log common
</VirtualHost>

<Directory /var/lib/tftpboot/images>
AllowOverride None
Options Indexes FollowSymlinks
Order allow,deny
Allow from all
</Directory>

Restart the httpd services

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

IMPORTANT NOTE:

Manually browse to the server ip (http://192.168.1.6/centos/6/i386/) and verify if you can see all the files.

FTP server

# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
anon_root=/var/lib/tftpboot/images

IMPORTANT NOTE:

Manually browse to the server ip (ftp://192.168.1.6/centos/6/i386/) and verify if you can see all the files.

Restart the services

# /etc/init.d/vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]

 

Configure TFTP server

Once these packages are installed copy the below files from the specified directory to /var/lib/tftpboot

# cp /usr/share/syslinux/pxelinux.0     /var/lib/tftpboot/
# cp /usr/share/syslinux/chain.c32     /var/lib/tftpboot/
# cp /usr/share/syslinux/menu.c32     /var/lib/tftpboot/
# cp /usr/share/syslinux/memdisk     /var/lib/tftpboot/
# cp /usr/share/syslinux/mboot.c32     /var/lib/tftpboot/

Next we will create the configuration file required for tftp server

# mkdir /var/lib/tftpboot/pxelinux.cfg

Create a new file "default" under "/var/lib/tftpboot/pxelinux.cfg" and add the below entry

For HTTP server

# vi /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu.c32
PROMPT 0
TIMEOUT 100
ONTIMEOUT Local

MENU TITLE PXE Menu

MENU seperator
LABEL CentOS 6.2
KERNEL images/centos/6/i386/images/pxeboot/vmlinuz
APPEND initrd=images/centos/6/i386/images/pxeboot/initrd.img method=http://192.168.1.6/centos/6/i386 devfs=nomount

MENU seperator
LABEL Local
LOCALBOOT 0

Here two things which you need to change
KERNEL - defines the location from where the PXELINUX bootloader will load
APPEND - defines the location for PXE initrd image file to load

For FTP server
There is not much change for ftp server just replace the below line in the above file

APPEND initrd=images/centos/6/i386/images/pxeboot/initrd.img method=ftp://192.168.1.6/centos/6/i386 devfs=nomount

Enable the tftp service in xinetd

# vi /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

Restart the relevant services

# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

Make sure your tftp server is working

Login to any target node within the same subnet network where you are planning to perform the PXE installation

Install tftp client

# yum install tftp

or you can also install using rpm as below

# rpm -Uvh /tmp/tftp-5.2-13.el7.x86_64.rpm
warning: /tmp/tftp-5.2-13.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:tftp-5.2-13.el7                  ################################# [100%]

Connect to your TFTP server

# tftp
(to) 192.168.1.6

As we see it is connected properly

tftp> status
Connected to 192.168.1.6.
Mode: netascii Verbose: off Tracing: off Literal: off
Rexmt-interval: 5 seconds, Max-timeout: 25 seconds

Next try to download a tftp file from the server

tftp> get linux-install/rhel7_64/vmlinuz
tftp> quit

Now check in the current path if the file exists

# ls vmlinuz
vmlinuz

So our tftp is working properly

IMPORTANT NOTE:

The same can be performed on localhost assuming you do not have any target node available to validate the TFTP, but it is always recommended to validate this from remote server as that way you can make sure there is no firewall or security policy which is blocking your tftp server from the client

 

Configure DHCP server

# vi /etc/dhcp/dhcpd.conf
option domain-name "example.com";
option domain-name-servers test.example.com;
default-lease-time 600;
max-lease-time 7200;
authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.1.20 192.168.1.25;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;

  allow booting;
        allow bootp;

        next-server 192.168.1.6;
        filename "pxelinux.0";
}

IMPORTANT NOTE:

In your dhcp server make sure you add these lines

next-server 192.168.1.6;
filename "pxelinux.0";

as these define the address of your tftp server and the file to look for after getting the IP Address from dhcp server

Restart the relevant services

# service dhcpd restart
Shutting down dhcpd:                                       [  OK  ]
Starting dhcpd:                                            [  OK  ]

Make sure the services start after reboot

# chkconfig httpd on
# chkconfig xinetd on
# chkconfig dhcpd on

 

Iptables rules

For DHCP server

# iptables -I INPUT -m state --state NEW -p udp --dport 69 -j ACCEPT

For HTTP server

# iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT

For FTP server

# iptables -I INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT

You are all set to test your PXE server. Boot a machine and select the option of Network Boot from Bios. You should see the below screen

IMPORTANT NOTE:

Validate your selinux policy as it may block the TFTP and DHCP servics, for me it is disabled.

# getenforceDisabled

How to configure PXE boot server in Linux using Red Hat 6
Related Articles:
What are the different types of Virtual Web Hosting in Apache
VSFTPD configuration
How to configure DHCP in Linux

17 thoughts on “How to configure PXE boot server in Linux using Red Hat 6”

  1. Try to access the page on your browser or using ftp client using proper authentication which is used in the configuration and see if you are getting any error to do the same.

    Check your firewall and selinux
    Look out in the logs for any hint which can guide you towards the issue.

    Reply
  2. hi
    am using rhel6.2....i got a warning message while i am starting the httpd service..../var/lib/tftp/images does not exist......but I hae the directory and mount iso to that directory....let me know what is the problem behind this....

    Reply
  3. My wild guess could be...In case you are following my article, I used /var/lib/tftpboot/images instead of /var/lib/tftp/images.

    So are you sure you have used the directory names properly?

    Reply
  4. Thans for your reply...Actually there is a problem in SELinux policy Permission mentioned in /var/log/messages...I cleared it by generating a local policy module....But There is an another problem...I completed all the steps you have mentioned and my client system get dhcp ip and get pxe boot menu...but it is not booting the os,after timeout it is booting from local drive...what is the problem?

    Reply
  5. I have never tried so cannot say 100% but I believe it should work when you copy the installation files and provide the source location. You can try and let us know as well.

    Thanks

    Reply
  6. Hi Meepak,
    mount /dev/sr0 /var/lib/tftpboot/images/centos/6/i386/
    mount: block device /dev/sr0 is write-protected, mounting read-only

    but operating system not found.
    please help me.

    Reply
  7. Hi achal, you can use system-config-kickstart in redhat and centos on GUI

    it will guide you step by step towards creating your own kickstart file.... use /root/anaconda-ks.cfg as reference

    Reply
  8. Check your firewall
    To troubleshoot these type of issues you can use tftp client and try to download the file locally or from target node, if it is accessible means your tftp is working fine

    Reply

Leave a Comment