Pages

Monday, June 5, 2017

How to create a PXE Boot server.

How to create a PXE ( Preboot eXecution Environment ) boot server

Pre-requisites

1) dhcp
2) tftp-server
3) syslinux
4) http/ftp (any one)

dhcp packages    : dhcp-3.0.7-7.5.20.x86_64.rpm & dhcp-server-3.0.7-7.5.20.x86_64.rpm
tftpboot package  : tftp-0.48-1.6.x86_64.rpm
pxeboot package : syslinux-3.11-20.14.26.x86_64.rpm

1) Prepare installation media on PXE server
2) Configure HTTP/FTP server 
3) Configure TFTP server
4) Change the owner and permission for /var/lib/tftpboot directory
5) Enable the tftp service in xinetd
6) Configure DHCP server

1) 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 below example we will be configuring 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/

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/

2) Configure HTTP/FTP server

You can use either HTTP/FTP 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.

With 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>

3) Configure TFTP server (Installing syslinux package)

Tftp configuration includes installation of syslinux package, pxelinux.0 file will be created under /usr/share/pxelinux/ directory. This is required to load,install kernel and initrd images on the client machine.

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" folder and add the below entries.

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 0Here 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

4) Change the owner and permission for /tftpboot directory

Assign nobody:nobody to /var/lib/tftpboot directory.

# chown nobody:nobody /var/lib//tftpboot
# chmod 777 /var/lib//tftpboot

5) 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  ]

6) 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

TIPS: 

next-server : statement is  used  to  specify  the  host address  of  the  server  from which the initial boot file (specified in the filename statement)  is  to  be  loaded. Server-name  should  be  a  numeric IP address or a domain name.

filename : option should be the name of the file which will be retrieved via TFTP the client filename pxelinux.0 is a boot loader.

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.

How PXE Boot Works and what is the use of TFTP and FTP/HTTP in PXE Boot


The PXE environment relies on a combination of UDP/IP, DHCP and TFTP. These are selected as they can be easily implemented in the client's NIC firmware, resulting in standardized small-footprint PXE ROMs. 

DHCP is used to provide the appropriate client network parameters and specifically the location (IP address) of the TFTP server hosting, ready for download, the initial bootstrap program (NBP) and complementary files. To initiate a PXE bootstrap session the DHCP component of the client's PXE firmware broadcasts a DHCPDISCOVER packet containing PXE-specific options to port 67/UDP (DHCP server port); it asks for the required network configuration and network booting parameters. The PXE-specific options identify the initiated DHCP transaction as a PXE transaction. Standard DHCP servers (non PXE enabled) will be able to answer with a regular DHCPOFFER carrying networking information (i.e. IP address) but not the PXE specific parameters. A PXE client will not be able to boot if it only receives an answer from a non PXE enabled DHCP server.


After parsing a PXE enabled DHCP server DHCPOFFER, the client will be able to set its own network IP address, IP Mask, etc., and to point to the network located booting resources, based on the received TFTP Server IP address and the name of the NBP. The client next transfers the NBP into its own random-access memory (RAM) using TFTP, possibly verifies it (i.e. UEFI Secure Boot), and finally boots from it. NBPs are just the first link in the boot chain process and they generally request via TFTP a small set of complementary files in order to get running a minimalistic OS executive (i.e. WindowsPE, or a basic Linux kernel+initrd). The small OS executive loads its own network drivers and TCP/IP stack. At this point, the remaining instructions required to boot or install a full OS are provided not over TFTP, but using a robust transfer protocol (such as HTTP, CIFS, or NFS).

No comments:

Post a Comment