Thursday, September 16, 2010

Configure PXE Server in Linux (For Installing OS Remotely)

In this article, we  discuss about how to setup pxeboot, including installation of necessary packages, and tftpboot configurations.
The Preboot eXecution Environment (PXE, and also known as Pre-Execution Environment) is an environment used to perform OS installation using a network interface on a remote machine for which you don’t have the physical access.The PXE protocol is approximately a combination of DHCP and TFTP. DHCP is used to locate the appropriate boot server or servers, with TFTP used to download the initial bootstrap program and additional files.
If a PXE redirection service (Proxy DHCP) receives an extended DHCPDISCOVER, it replies by broadcasting a DHCPOFFER packet extended with PXE-specific options (extended DHCPOFFER) to port 68/UDP (DHCP client port). This packet has to be broadcast, since most PXE clients will configure themselves by DHCP and cannot provide their IP ADDRESS in the extended DHCPDISCOVER. Therefore the client is identified by its GUID/UUID.
An extended DHCPOFFER contains mainly:
  • a PXE Discovery Control field to decide whether Multicasting, Broadcasting or unicasting is to be used for contacting PXE boot servers
  • a list of IP addresses of each available PXE Boot Server Type
  • a PXE Boot Menu with each entry representing a PXE Boot Server Type
  • a PXE Boot Prompt telling the user to press <F8> to see the boot menu
  • a timeout to launch the first boot menu entry if it expires.
The Proxy DHCP service may also be run on the same host as the standard DHCP service. Since both services cannot share port 67/UDP, the Proxy DHCP runs on port 4011/UDP and expects the extended DHCPDISCOVER packets from PXE Clients to be DHCPREQUESTs. The standard DHCP service has to send a special combination of PXE options in its DHCPOFFER, so the PXE client knows to look for a Proxy DHCP on the same host, port 4011/UDP.
 In order to perform the OS installation successfully, there should be a way to reboot the remote server — We are performing Remote Installation through taking session on LogMeIn and the servers to be installed are connected on IP KVM Switch on different ports, but there are some other ways also.
Required Packages
The following packages needs to be installed for the tftpboot setup.
  • dhcp services packages: dhcp-3.0.7-7.5.20.x86_64.rpm and 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

Package Installation

Install the packages for the dhcp server services:
# rpm -ivh dhcp-3.0.7-7.5.20.x86_64.rpm
Preparing...                ########################################### [100%]
   1:dhcp                   ########################################### [100%]

# rpm -ivh dhcp-server-3.0.7-7.5.20.x86_64.rpm
Preparing...                ########################################### [100%]
   1:dhcp                   ########################################### [100%]

# rpm -ivh tftp-0.48-1.6.x86_64.rpm

# rpm -ivh syslinux-3.11-20.14.26.x86_64.rpm
After installing the 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.
Verify that the packages are successfully installed.
# rpm -qa | grep dhcp
# rpm -qa | grep tftp
Download the appropriate tftpserver from the repository of your respective Linux distribution.

Steps to setup tftpboot

Step 1: Create /tftpboot directory

Create the tftpboot directory under root directory ( / ) as shown below.
# mkdir /tftpboot/

Step 2: Copy the pxelinux image

PXE Linux image will be available once you installed the syslinux package. Copy this to /tftpboot path as shown below.
# cp /usr/share/syslinux/pxelinux.0 /tftpboot

Step 3: Create the mount point for ISO and mount the ISO image

Let us assume that we are going to install the Ubuntu 9.10 Debian Linux distribution on a remote server. If you have the Ubuntu 9.10 DVD insert it in the drive or mount the ISO image which you have. Here, the iso image has been mounted as follows:
# mkdir /tftpboot/ubuntu_9.10

# mount -o loop  ubuntu-9.10-server-i386.iso /tftpboot/ubuntu_9.10

Step 4: Copy the vmlinuz and initrd images into /tftpboot

Copy the initrd to the tftpboot directory as shown below.
# cd /tftpboot/ubuntu_9.10/boot/x86_64/loader

# cp initrd linux /tftpboot/

Step 5: Create pxelinux.cfg Directory

Create the directory pxelinux.cfg under /tftpboot and define the pxe boot definitions for the client.
# mkdir /tftpboot/pxelinux.cfg

# cat >/tftpboot/pxelinux.cfg/default
default linux
label linux
kernel linux
append initrd=initrd showopts instmode=nfs install=nfs://192.168.1.101/tftpboot/ubuntu_9.10/
The following options are used for,
  • kernel – specifies where to find the Linux install kernel on the TFTP server.
  • install – specifies boot arguments to pass to the install kernel.
As per the entries above, the nfs install mode is used for serving install RPMs and configuration files.

Step 6: Change the owner and permission for /tftpboot directory

Assign nobody:nobody to /tftpboot directory.
# chown nobody:nobody /tftpboot

# chmod 777 /tftpboot

Step 7: Modify /etc/dhcpd.conf

Modify the /etc/dhcpd.conf as shown below.
# cat /etc/dhcpd.conf

ddns-update-style none;
default-lease-time 14400;
filename "pxelinux.0"; 

# IP address of the dhcp server nothing but this machine.
next-server 192.168.1.101;
subnet 192.168.1.0 netmask 255.255.255.0 {
  # ip distribution range between 192.168.1.1 to 192.168.1.100
  range 192.168.1.1 192.168.1.100;
  default-lease-time 10;
  max-lease-time 10;
}
Specify the interface in /etc/syslinux/dhcpd to listen dhcp requests coming from clients.
# cat /etc/syslinux/dhcpd | grep DHCPD_INTERFACE
DHCPD_INTERFACE=”eth1”;
Here, this machine has the ip address of 192.168.1.101 on the eth1 device. So, specify eth1 for the DHCPD_INTERFACE as shown above.

Step 8: Modify /etc/xinetd.d/tftp

Modify the /etc/xinetd.d/tftp file to reflect the following. By default the value for disable parameter is “yes”, please make sure you modify it to “no” and you need to change the server_args entry to -s /tftpboot.
# cat /etc/xinetd.d/tftp
 service tftp {
                       socket_type     = dgram
                       protocol          = udp
                       wait               = yes
                       user               = root
                       server            = /usr/sbin/in.tftpd
                       server_args     = -s /tftpboot
                       disable           = no
            }

Step 9: No changes in /etc/xinetd.conf

There is no need to modify the etc/xinetd.conf file. Use the default values specified in the xinetd.conf file.

Step 10: Restart xinetd, dhcpd and nfs services

Restart these services as shown below.
# /etc/init.d/xinetd restart

# /etc/init.d/dhcpd restart

# /etc/init.d/nfsserver restart
After restarting the nfs services, you can view the exported directory list(/tftpboot) by the following command,
# showmount -e
Finally, the tftpboot setup is ready and now the client machine can be booted after changing the first boot device as “network” in the BIOS settings.
If you encounter any tftp error, you can do the troubleshooting by retrieving some files through tftpd service.
Retrieve some file from the tftpserver to make sure tftp service is working properly using the tftp client. Let us that assume that pankaj.doc file is present under /tftpboot directory.
# tftp -v 192.168.1.101 -c get pankaj.doc


Note that this document comes without warranty of any kind. But every effort has been made to provide the information as accurate as possible. I welcome emails from any readers with comments, suggestions, and corrections at webmaster_at admin@linuxhowto.in

Copyright © 2012 LINUXHOWTO.IN

No comments:

Post a Comment