PXE/Network boot Server on Linux

This documents how to setup a PXE boot server for Linux. This assumes that you're using Redhat as the PXE boot server.

0) The first thing to note is that you need to setup your own mini-network that is completely disconnected from the network, since part of this process requires setting up a DHCP server which could conflict with the corporate DHCP server if they were both running on the same network simultaneously. So get yourself a switch from IT up front. You do *NOT* need the switch immediately, so just put it aside until I mention it again later on.

1) The next step is to choose a box to be the PXE boot server. This can really be any box at all, as long as you have a NIC in it that works reliably under Linux. For the purposes of this documentation, I'm going to assume that you've loaded Fedora Core 4 on this box (do that now, if you've not already). Get this box onto the network with DHCP (just like a normal installation).

2) Next you'll need to install the following:

tftp-server
dhcp
httpd
syslinux

If you use yum to install them, then it will be generally alot easier:

yum install tftp-server dhcp httpd syslinux

answer Y to all dependency/installation questions.

3) Now you need to setup the DHCP server. Edit the file: /etc/dhcp/dhcpd.conf with the following contents:

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
option domain-name-servers 142.133.79.11, 142.133.78.11;
option ntp-servers 10.121.122.17;
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
ddns-update-style none;
ignore client-updates;
allow bootp;
allow booting;
max-lease-time 14400;
default-lease-time 1800;
subnet 10.121.122.0 netmask 255.255.255.224 {
  option routers 10.121.122.1;
  range dynamic-bootp 10.121.122.18 10.121.122.30;
  filename "pxelinux.0";
  next-server 10.121.122.17;
}

4) Next you need to activate tftp within xinetd.
All that is neccesary is to change disable=yes to disable=no in /etc/xinetd.d/tftp
Start xinetd and tftp on for chkconfig
# chkconfig xinetd on
#chkconfig tftp on
 Then restart xinetd.
# Service xinetd start

5) Now we need to setup your PXE server to use a static IP on the new private subnet. Create the file /etc/sysconfig/network-scripts/ifcfg-eth0.static with the following contents:

DEVICE=eth0
BOOTPROTO=STATIC
ONBOOT=no
TYPE=Ethernet
IPADDR=10.121.122.17
NETMASK=255.255.255.254
GATEWAY=10.121.122.1

6) Mount the ISO image to the kickstart server first in mnt directory:

# mount -o loop /home/long/rhel-server-6.3-x86_64-dvd.iso   /mnt/images/rh63/x86_64/

7) Now we need to setup the PXE boot environment on the server.
On the first CD of every RH distribution there is a subdirectory called 'isolinux'.
 In that directory you will find two files, vmlinuz and initrd.img. These are the kernel & initrd.img that the RH bootable CDs use to get the installer (anaconda) booted for performing the installation. Copy both of those files into /tftpboot and make sure that they are world readable.
# mkdir /tftpboot
# mkdir /tftpboot/rh63
# cd /mnt/images/rh63/x86_64/isolinux/
# cp  vmlinuz /tftpboot/rh63/
# cp initrd.img /tftpboot/rh63/
If you are planning to allow more than one version/distribution to be PXE boot installable, then you should rename both files so that its clear that they are for whatever version/distribution they came from (such as vmlinuz-rhel63, initrd-rhel63).

Next, you need the actual pxe boot linux kernel (what is actually run immediately after your PXE boot client box gets a DHCP lease). In this case, that file is pxelinux.0 and  menu.c32, and is part of the syslinux RPM. For RH63, you can find it at /usr/share/syslinux dir. Copy both file into /tftpboot and make sure that it is world readable.
# locate –ipxelinux.0
/usr/share/syslinux/pxelinux.0
# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
# locate –I menu.c32
/usr/share/syslinux/menu.c32
# cp /usr/share/syslinux/menu.c32 /tftpboot/

At this point, the setup can be done in two ways:   NFS or HTTPD
Method 1:NFS ( assuming NFS is already installed in the kickstart server)
8) Edit the export file of NFS server like below:
# See the exports(5) manpage for a description of the syntax of this file.
# This file contains a list of all directories that are to be exported to
# other computers via NFS (Network File System).
# This file used by rpc.nfsd and rpc.mountd. See their manpages for details
# on how make changes in this file effective.

#/distros       *(fsid=0,ro,sync,root_squash,no_subtree_check)
/distros        *(ro,sync,root_squash,no_subtree_check)
/mnt/images/rh63/x86_64/      *(ro,sync,root_squash,no_subtree_check)


8) Now create the default pxelinux configuration inside the new file:
# mkdir /tftpbot/pxelinux.cfg
Optional: it may require in some case
# mkdir /tftpbot/pxelinux.cfg/rhel63
## cd /mnt/images/rh63/x86_64/isolinux/
# cp  vmlinuz /tftpbot/pxelinux.cfg/rhel63
# cp initrd.img /tftpbot/pxelinux.cfg/rhel63

# vi /tftpboot/pxelinux.cfg/default:

PROMPT 0
DEFAULT menu.c32
MENU TITLE Linux Distribution Selection
LABEL RHEL63x86X64MANUAL
        MENU LABEL RHEL 6.3 Server x64 Manual Install
        KERNEL rhel63/vmlinuz
 APPEND linux dd load_ramdisk=1 initrd=rhel63/initrd.img  method=nfs://10.121.122.17:/mnt/images/rh63/x86_64 ip=dhcp

10) Now start dhcpd & apache and activate tftp by running the following:
service dhcpd start
service xinetd restart
service nfs start

Method 2 : HTTP
8) Now create the default pxelinux configuration inside the new file:
# mkdir /tftpbot/pxelinux.cfg

Optional: it may require in some case
# mkdir /tftpbot/pxelinux.cfg/rhel63
## cd /mnt/images/rh63/x86_64/isolinux/
# cp  vmlinuz /tftpbot/pxelinux.cfg/rhel63
# cp initrd.img /tftpbot/pxelinux.cfg/rhel63

#vi /tftpboot/pxelinux.cfg/default:

prompt 1
default linux
timeout 100

label linux
kernel vmlinuz
append initrd=initrd.img ramdisk_size=9216 noapic acpi=off



9) Now you need to put the full contents of your Linux distro (all CDs) somewhere on disk. I put it under /tftpboot/rhel63. In order to allow for installation over HTTP (apache), edit the file and restart the httpd service
/etc/httpd/conf/httpd.conf and add the following:


< Directory /tftpboot/rhel63 >
Options Indexes
AllowOverride None
< /Directory >
Alias /linux /tftpboot/rhel63

10) Now start dhcpd & apache and activate tftp by running the following:
service dhcpd start
service xinetd restart
service httpd start

and verify that they are all in your process list.

Now from the client machine use NET/PXE boot to use kickstart server image to install OS in all servers.

Ref:
1. Source:  http://www.linux-sxs.org/internet_serving/pxeboot.html

Comments

Popular Posts